+ Post New Thread
Results 1 to 12 of 12
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 ...
  1. #1

    Join Date
    Feb 2008
    Posts
    325
    Thank Post
    51
    Thanked 3 Times in 3 Posts
    Rep Power
    14

    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

  2. #2

    vikpaw's Avatar
    Join Date
    Sep 2006
    Location
    Saudi Arabia
    Posts
    5,848
    Thank Post
    671
    Thanked 1,383 Times in 1,145 Posts
    Rep Power
    350
    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.

  3. #3
    Dom_'s Avatar
    Join Date
    Dec 2008
    Posts
    1,009
    Thank Post
    151
    Thanked 138 Times in 115 Posts
    Rep Power
    56
    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'

  4. #4

    powdarrmonkey's Avatar
    Join Date
    Feb 2008
    Location
    Alcester, Warwickshire
    Posts
    4,859
    Thank Post
    412
    Thanked 777 Times in 650 Posts
    Rep Power
    182
    ntbackup in copy mode.

  5. #5

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,710
    Thank Post
    3,246
    Thanked 1,048 Times in 970 Posts
    Rep Power
    364
    Quote Originally Posted by jinnantonnix View Post
    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

  6. Thanks to mac_shinobi from:

    itgeek (1st December 2009)

  7. #6

    Join Date
    Feb 2008
    Posts
    325
    Thank Post
    51
    Thanked 3 Times in 3 Posts
    Rep Power
    14
    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!!

  8. #7
    buzzard's Avatar
    Join Date
    May 2006
    Location
    North West
    Posts
    299
    Thank Post
    103
    Thanked 27 Times in 23 Posts
    Rep Power
    24
    another vote for Robocopy, both with and without the GUI!

  9. #8

    Join Date
    Feb 2008
    Posts
    325
    Thank Post
    51
    Thanked 3 Times in 3 Posts
    Rep Power
    14
    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

  10. #9
    buzzard's Avatar
    Join Date
    May 2006
    Location
    North West
    Posts
    299
    Thank Post
    103
    Thanked 27 Times in 23 Posts
    Rep Power
    24
    or use the GUI and tick the "save as script" tickbox they always work for me!

  11. Thanks to buzzard from:

    itgeek (1st December 2009)

  12. #10

    Join Date
    Feb 2008
    Posts
    325
    Thank Post
    51
    Thanked 3 Times in 3 Posts
    Rep Power
    14
    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

  13. #11

    Join Date
    Feb 2008
    Posts
    325
    Thank Post
    51
    Thanked 3 Times in 3 Posts
    Rep Power
    14
    got it /e



    thanks again for all the help

  14. #12

    teejay's Avatar
    Join Date
    Apr 2008
    Posts
    3,174
    Thank Post
    284
    Thanked 773 Times in 583 Posts
    Rep Power
    335
    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:
+ Post New Thread

Similar Threads

  1. copy only certain file types between folders..
    By kennysarmy in forum Windows
    Replies: 3
    Last Post: 2nd April 2009, 12:41 PM
  2. Copy file across variable folder name
    By SimpleSi in forum *nix
    Replies: 11
    Last Post: 10th March 2009, 06:15 PM
  3. File copy tool
    By kerrymoralee9280 in forum How do you do....it?
    Replies: 5
    Last Post: 7th March 2008, 12:19 PM
  4. Copy a file to many destination folders.
    By fooby in forum Windows
    Replies: 1
    Last Post: 14th June 2006, 02:18 PM
  5. Replies: 4
    Last Post: 23rd March 2006, 06: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
  •