Scripts Thread, Copy New file from A to B in Coding and Web Development; Hi I want to copy only new files created on the day to be copied to another location is this ...
-
1st December 2009, 01:11 PM #1
- Rep Power
- 9
Copy New file from A to B
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
-
-
IDG Tech News
-
1st December 2009, 01:33 PM #2 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 :
Code:
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.
-
-
1st December 2009, 01:47 PM #3 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'
-
-
1st December 2009, 01:54 PM #4
-
-
1st December 2009, 02:06 PM #5 
Originally Posted by
jinnantonnix
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
-
Thanks to mac_shinobi from:
itgeek (1st December 2009)
-
1st December 2009, 03:01 PM #6
- Rep Power
- 9
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!!
-
-
1st December 2009, 03:15 PM #7 another vote for Robocopy, both with and without the GUI!
-
-
1st December 2009, 03:19 PM #8
- Rep Power
- 9
So its something like this??
C:\Program Files\Windows Resource Kits\Tools>robocopy <i:\Backup FilesB> <i:\Bac
kup Files> /MAXAGE:1
Sorry!!
Thanks again
-
-
1st December 2009, 03:23 PM #9 or use the GUI and tick the "save as script" tickbox
they always work for me!
-
Thanks to buzzard from:
itgeek (1st December 2009)
-
1st December 2009, 03:30 PM #10
- Rep Power
- 9
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
-
-
1st December 2009, 03:31 PM #11
- Rep Power
- 9
got it /e
thanks again for all the help
-
-
1st December 2009, 03:38 PM #12 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
-
SHARE:
Similar Threads
-
By kennysarmy in forum Windows
Replies: 3
Last Post: 2nd April 2009, 12:41 PM
-
By SimpleSi in forum *nix
Replies: 11
Last Post: 10th March 2009, 07:15 PM
-
By kerrymoralee9280 in forum How do you do....it?
Replies: 5
Last Post: 7th March 2008, 01:19 PM
-
By fooby in forum Windows
Replies: 1
Last Post: 14th June 2006, 02:18 PM
-
By tosca925 in forum Scripts
Replies: 4
Last Post: 23rd March 2006, 07:27 AM
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules