none
Robocopy copie only the the newest file RRS feed

  • Question

  • Hello,

    I want to copy only the newest file from source directory using robocopy 

    Robocopy "N:\source" "H:\bak" "Nss_GT_??.bak" /XO

    but I copy all files with the same pattern. 

    How can I do it?

    Tuesday, December 2, 2014 3:34 PM

Answers

  • You can do this in PowerShell. The code would look something like this (not tested):


    $newest = get-childitem "NSS_GT_??.bak" | sort-object LastWriteTime | select-object -last 1
    robocopy "N:\BTSQLNSS01" "H:\BAK" $newest.Name
    



    -- Bill Stewart [Bill_Stewart]

    Monday, February 2, 2015 8:00 PM
    Moderator

All replies

  • Hello,

    I want to copy only the newest file from source directory using robocopy 

    Robocopy "N:\source" "H:\bak" "Nss_GT_??.bak" /XO

    but I copy all files with the same pattern. 

    How can I do it?

    RoboCopy has no "newest" argument.   "Newest" is ambiguous.  "Newest" compared to what?

    Post RoboCopy questions in the platform forum for the OS you are using.  They work with the Windows utilities.  This is a scripting forum for Admin scripting. RoboCopy is not a script.


    ¯\_(ツ)_/¯

    Tuesday, December 2, 2014 4:04 PM
  • In source directory "Nss_GT_??.bak"

    I have several file with the same pattern but I want retrieve only one the last modified file.


    Tuesday, December 2, 2014 4:16 PM
  • What version of scripting are you running?  What version of Windows?

    ¯\_(ツ)_/¯

    Tuesday, December 2, 2014 4:19 PM
  • I use 5.2.3790 Version of scripting and windows server 2003  
    Tuesday, December 2, 2014 5:31 PM
  • I use 5.2.3790 Version of scripting and windows server 2003  

    What scripting? Post the script.

    ¯\_(ツ)_/¯

    Tuesday, December 2, 2014 5:41 PM
  • I use only command line in Bat file. 

    @echo off
    Robocopy "N:\BTSQLNSS01" "H:\bak" "Nss_GT_??.bak" /XO 

    Pause

    REM ********************************************
    REM ************** FIN DU BATCH ****************
    REM ********************************************

    Wednesday, December 3, 2014 10:35 AM
  • You can do this in PowerShell. The code would look something like this (not tested):


    $newest = get-childitem "NSS_GT_??.bak" | sort-object LastWriteTime | select-object -last 1
    robocopy "N:\BTSQLNSS01" "H:\BAK" $newest.Name
    



    -- Bill Stewart [Bill_Stewart]

    Monday, February 2, 2015 8:00 PM
    Moderator