computing
  • 0

XCOPY Yesterday Date Parameter

  • 0

I need to copy everyday automatically, the files that were created or changed yesterday into a new folder(no syncronization only copy), I am trying with XCOPY but in the Date parameter do not accept variables.
This is the script.

PowerShell $date = Get-Date; $date=$date.AddDays(-1); $date.ToString(‘MM-dd-yyyy’)
xcopy C:\test C:\copy /D:$date /E

Any Idea?

Share

1 Answer

  1. Whenever someone writes to a file, the archive attribute is turned on. Running XCOPY /M copies only files with the archive attribute set, and then turns the attribute off. You end up coping only files that have been modified since the last time you ran XCOPY /M.

    The first time you run it will end up with the entire directory structure copied. This is because you’ve never ran a backup on those files before. (Note: You can manually turn off the attribute before the first run.) After that, it’ll be every file that has been modified since the last run.

    EDIT:
    Turn off archive attribute for a directory branch:

    attrib c:\test\* -a /s

    View files with archive attribute set:

    dir /aa c:\test

    How To Ask Questions The Smart Way

    • 0