itgeek Posted December 1, 2009 Posted December 1, 2009 Hi I want to copy only new files created on the day to be copied to another location is this possible? Thanks This gets the latest file but not all the files that were created! Dim fNewest set oFolder=createobject("scripting.filesystemobject").getfolder("\\dylan\d$\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Backup") For Each aFile In oFolder.Files If fNewest = "" Then Set fNewest = aFile Else If fNewest.DateCreated < aFile.DateCreated Then Set fNewest = aFile End If End If Next Msgbox fNewest.Name
vikpaw Posted December 1, 2009 Posted December 1, 2009 my coding is poor, but what you are doing is looping through an array of files objects in the specified folder and each time one is newer it replaces the fNewest variable. (just had to say it out in pseudo-code). if you want to capture all files from today you need to put in some kind of date function and check the creation / modified dates on the actual files. also, your for...next loop needs to have a counter such that rather than a flat variable fNewest, you fill an array with a list of names. next you need to handle the actual copying part. it seems quite complicated, if it's just for a some personal use specifically for backups. have you considered a batch file using xcopy, you can simply schedule : xcopy /d:m-d-y source destination something like that, obviously need to capture the date too using %date% and do some extraction of the d/m/y parts to feed into xcopy, but relatively trivial. i had a script somewhere that did something similar and woud back up an access db to a separate location in a dated folder. will try and look it up if no-one else comes back sooner. also, check the MIS forum for a handly little backup tool that may be of use to you as well.
Dom_ Posted December 1, 2009 Posted December 1, 2009 Karen's replicator allows you to do this, but will copy updated files too... Check the box saying 'only copy file if changed or added'
mac_shinobi Posted December 1, 2009 Posted December 1, 2009 Good old ROBOCOPY can do most things. This sort of task is right up its street. /MAXAGE:n :: MAXimum file AGE - exclude files older than n days/date. /MINAGE:n :: MINimum file AGE - exclude files newer than n days/date. /MAXLAD:n :: MAXimum Last Access Date - exclude files unused since n. /MINLAD:n :: MINimum Last Access Date - exclude files used since n. (If n < 1900 then n = n days, else n = YYYYMMDD date). You want to use the /MAXAGE:1 which will exclude files over a day old. Think you can also get the GUI for robocopy so makes it a bit easier Utility Spotlight: Robocopy GUI 1
itgeek Posted December 1, 2009 Author Posted December 1, 2009 So The solutions will only copy new files to a dir. In the new dir they will not be all the files but only the new files and a cleanup will be run to delete old files. Thanks again. Sorry its hard to explain!!
buzzard Posted December 1, 2009 Posted December 1, 2009 another vote for Robocopy, both with and without the GUI!
itgeek Posted December 1, 2009 Author Posted December 1, 2009 So its something like this?? C:\Program Files\Windows Resource Kits\Tools>robocopy kup Files> /MAXAGE:1 Sorry!! Thanks again
buzzard Posted December 1, 2009 Posted December 1, 2009 or use the GUI and tick the "save as script" tickbox they always work for me! 1
itgeek Posted December 1, 2009 Author Posted December 1, 2009 Thanks so much its working great just one small problem its not copying folders only files in the root. robocopy "I:\Backup Files" "I:\Backup FilesB" /MAXAGE:1
itgeek Posted December 1, 2009 Author Posted December 1, 2009 got it /e thanks again for all the help
teejay Posted December 1, 2009 Posted December 1, 2009 If you want to maintain permissions and ownership of the files, add /COPYALL You may also want to add /ZB which gives greater resilience in the copy process
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now