none
robocopy /copy:DA but without T atribute (ignore timestamps on files)

    Question

  • Hello

    i notice that robocopy not working with /copy:DA, when I add D flag it always run with T flag. I need to ignore files timestamps and create new ones in destination folder. 

    Anyone know workarround to this issue ?



    • Edited by Piterooo Friday, November 3, 2017 3:13 PM
    Friday, November 3, 2017 10:56 AM

Answers

  • Thanks for info, but what a shame. Except this issue Robocopy would be a perfect tool. I figured out solution with adding to my batch script, simple PowerShell script which updates CreationTime of copied files.

    You have to declare "path" variable which will be used in PS script as a "env" variable (enviroment). After robocopy is succesfuly done script calls "timestamps" PS script which updates time attributes of folders and files in "path" variable with current date.

    SET /p s=source ?:
    SET /p d=destination?:
    SET path_dest=%d%
    RoboCopy.exe "%s%" "%d%" *.* /E /B /MT:8 R:99 /XJD /XD %xddir% /ETA /TEE /LOG+:"C:\temp\robo.log"
    if %errorlevel% EQU 1 goto timestamp
    if %errorlevel% NEQ 1 goto error
    
    :timestamps
    start /b powershell -ExecutionPolicy Bypass -file "c:\temp\timestamps.ps1" 

    Function Set-FileTimeStamps {
    
    
     Param (
    
        [Parameter(mandatory=$true)]
    
        [string[]]$path,
    
        [datetime]$date = (Get-Date))
    
        
        Get-ChildItem -ErrorAction silentlyContinue -Recurse -Force -Path $path |
    
        ForEach-Object {
    
         $_.CreationTime = $date
    
         $_.LastAccessTime = $date
    
         $_.LastWriteTime = $date
         
          }
    
    } 
    
    [datetime]$date = (Get-Date)
    Set-FileTimeStamps -ErrorAction silentlyContinue -path $Env:path_dest -date $date





    • Marked as answer by Piterooo Monday, November 6, 2017 1:28 PM
    • Edited by Piterooo Friday, November 10, 2017 3:09 PM
    Monday, November 6, 2017 1:26 PM

All replies

  • Interesting if you look at the what robocopy runs (in the first section it outputs when run) it does add the T.

    Looking at Robocopy - how to discard timestamps others have noticed that and appears to be related to the way robocopy works by comparing timestamps. So as that post what are you trying to achieve overall? Perhaps another way to achieve that.

    Saturday, November 4, 2017 10:11 PM
  • Hi Piterooo,

    Based on my search, it would appear the undocumented behavior is as follows:

    Whenever, the D flag is used for /COPY, robocopy will automatically add the T flag.

    However, this does not apply to the directory /DCOPY flag. It can be specified without T and work.

    This is by design, and also it is not undocumented.

    According to the Robocopy Documentation:

    Note: If file Data is copied, then file Timestamps are also copied.

    Some people tested it below.

    /Copy:D becomes /Copy:DT

    /Copy:A becomes /DCopy:DA /Copy:A

    /Copy:T becomes /DCopy:D /Copy:T

    /Copy:DT becomes /DCopy:D /Copy:DT

    /Copy:AT becomes /DCopy:DA /Copy:AT

    Hope it will be helpful to you


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Monday, November 6, 2017 9:37 AM
    Moderator
  • Thanks for info, but what a shame. Except this issue Robocopy would be a perfect tool. I figured out solution with adding to my batch script, simple PowerShell script which updates CreationTime of copied files.

    You have to declare "path" variable which will be used in PS script as a "env" variable (enviroment). After robocopy is succesfuly done script calls "timestamps" PS script which updates time attributes of folders and files in "path" variable with current date.

    SET /p s=source ?:
    SET /p d=destination?:
    SET path_dest=%d%
    RoboCopy.exe "%s%" "%d%" *.* /E /B /MT:8 R:99 /XJD /XD %xddir% /ETA /TEE /LOG+:"C:\temp\robo.log"
    if %errorlevel% EQU 1 goto timestamp
    if %errorlevel% NEQ 1 goto error
    
    :timestamps
    start /b powershell -ExecutionPolicy Bypass -file "c:\temp\timestamps.ps1" 

    Function Set-FileTimeStamps {
    
    
     Param (
    
        [Parameter(mandatory=$true)]
    
        [string[]]$path,
    
        [datetime]$date = (Get-Date))
    
        
        Get-ChildItem -ErrorAction silentlyContinue -Recurse -Force -Path $path |
    
        ForEach-Object {
    
         $_.CreationTime = $date
    
         $_.LastAccessTime = $date
    
         $_.LastWriteTime = $date
         
          }
    
    } 
    
    [datetime]$date = (Get-Date)
    Set-FileTimeStamps -ErrorAction silentlyContinue -path $Env:path_dest -date $date





    • Marked as answer by Piterooo Monday, November 6, 2017 1:28 PM
    • Edited by Piterooo Friday, November 10, 2017 3:09 PM
    Monday, November 6, 2017 1:26 PM
  • Hi Piterooo,

    Glad to hear that you have found a solution and thank you for sharing it here, it will be helpful to other community members who have same questions.

    If the reply is helpful, please remember to mark it as answer which can help other community members who have same questions and find the helpful reply quickly.

    If any further help needed, please feel free to post back.

    Best regards,

    Carl


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.


    Monday, November 6, 2017 1:43 PM
    Moderator