Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


copy directory structure w/date exception

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,64075
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> copy directory structure w/date exception
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 copy directory structure w/date exception - 9/5/2008 10:59:59 AM   
  knoviello

 

Posts: 2
Score: 0
Joined: 9/5/2008
Status: offline
I am trying to copy and retain the directory structure of a given folder with all its folders and files to another location. Also I need it to copy files only older than 1 month. As you can see I have started the script below but it is so inadequate right now. Any help is appreciated. I searched the forums for a while but couldn't find relevant info sorry if this is a common question.


Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("\\Source")

Set colFiles = objFolder.Files

dtmMonthAgo = DateAdd("m", -1, Now)

For Each objFile in colFiles
   If objFile.DateLastModified < dtmMonthAgo Then
       objFSO.MoveFile objFile.Path, "\\Destination"
  
   End If
  
Next

 
 
Post #: 1
 
 RE: copy directory structure w/date exception - 9/5/2008 12:38:14 PM   
  dm_4ever


Posts: 2637
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
Why bother with a script when Robocopy.exe can probably do it for you?

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to knoviello)
 
 
Post #: 2
 
 RE: copy directory structure w/date exception - 9/7/2008 5:57:32 AM   
  knoviello

 

Posts: 2
Score: 0
Joined: 9/5/2008
Status: offline
Good point and so I did. Its working for me so far. here is what I did:

@echo off
set folder=%date:~10,4%%date:~4,2%%date:~7,2%
SET D2=\\FTPServer
SET l1=\\Server1
robocopy %l1%\d$\logs %D2%\temp\%l1%_%folder% /minage:30

What this does is copy all folders and files older than 30 days from l1(server1) to D2(ftp server) and names the folder: hostname_current date

Now I have a question, i need to do this for many more servers, is there a better way than declaring each one like so?:

@echo off
set folder=%date:~10,4%%date:~4,2%%date:~7,2%
SET D2=\\FTPServer
SET l1=\\Server1
SET l2=\\Server2
SET l3=\\Server3
SET l4=\\Server4
SET l5=\\Server5
SET l6=\\Server6
SET l7=\\Server7
SET l8=\\Server8
SET l9=\\Server9
SET l10=\Server10
SET l11=\\Server11
SET l12=\\Server12
SET l13=\\Server13
robocopy %l1%\d$\logs %D2%\temp\%l1%_%folder% /minage:30
robocopy %l2%\d$\logs %D2%\temp\%l2%_%folder% /minage:30
robocopy %l3%\d$\logs %D2%\temp\%l3%_%folder% /minage:30
robocopy %l4%\d$\logs %D2%\temp\%l4%_%folder% /minage:30
robocopy %l5%\d$\logs %D2%\temp\%l5%_%folder% /minage:30
robocopy %l6%\d$\logs %D2%\temp\%l6%_%folder% /minage:30
robocopy %l7%\d$\logs %D2%\temp\%l7%_%folder% /minage:30
robocopy %l8%\d$\logs %D2%\temp\%l8%_%folder% /minage:30
robocopy %l9%\d$\logs %D2%\temp\%l9%_%folder% /minage:30
robocopy %l10%\d$\logs %D2%\temp\%l10%_%folder% /minage:30
robocopy %l11%\d$\logs %D2%\temp\%l11%_%folder% /minage:30
robocopy %l12%\d$\logs %D2%\temp\%l12%_%folder% /minage:30
robocopy %l13%\d$\logs %D2%\temp\%l13%_%folder% /minage:30

< Message edited by knoviello -- 9/7/2008 6:00:24 AM >

(in reply to dm_4ever)
 
 
Post #: 3
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> copy directory structure w/date exception Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts