• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3314
  • Last Modified:

How to write a vbscript to copy files recently modified but keep the folder sructure as well?

Hi,

I am trying to write a vbscript that copies the contents of a folder (files and folder structure) to another folder, but ONLY where the files have been modified/created in the previous day.

I've found plenty of examples of how to copy files, folders or both, but I'm unsure how to go about selectively copying by modified date. For example, I'm fairly sure I could copy all files from a folder and subfolders into a single folder, but then I'd loose the original foldder struture... The key here is that I want to keep the folder structure of the files but only copy the recently modified ones...

Hope that makes sense!
0
grjitdept
Asked:
grjitdept
3 Solutions
 
LauraEHunterMVPCommented:
Why not just use xcopy instead of vbscript?  It will maintain the folder structure, and there's a switch where, if the files already exist at the destination, to only copy files/folders that are newer than those already in place.  (I think it's the -d switch, but xcopy /? will give you a list of all available.)
0
 
KCTSCommented:
Why write a script when you can do it with Xcopy

xcopy c:\source  d:\backup  /y /i /f /e
will copy all files and folder structure from c:\source to d:\backup - do this once in a while and at least once before...


xcopy c:\source  d:\backup /m /y /i /f /e

which will copy any files from c:\source to d:\backup if they have the been changed since they were last copied - run this regularly

http://www.ss64.com/nt/xcopy.html
0
 
grjitdeptAuthor Commented:
I've just read up on xcopy and it seems that would do the trick nicely! I'm still curious if there is a simple and effective way of doing a similar thing in vbscript so I'll the question open a bit longer...
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
KCTSCommented:
ah yes the /d switch - you could use that as well/instead - see the link i gave earlier.
0
 
RobSampsonCommented:
Hi, in short, no, VBScript would not do this any easier, nor any faster.  XCopy would definately be the way to go, however, to incorporate that *into* a VBS script, just add these lines:

Set objShell = CreateObject("WScript.Shell")
strCommand = "XCopy /d:10-01-2007 /E /C /I /H /R /K /X /Y C:\SourceFolder C:\DestFolder"
objShell.Run strCommand, 1, True

You can change the 1 in the objShell.Run line to a 0 to hide the command prompt while it copies....

Regards,

Rob.
0
 
HusbiCommented:
Use robocopy to Mirror

See http://www.ss64.com/nt/robocopy.html
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now