XCOPY command works with both /D:date and /Exclude: together?

Jane Jie Chen 506 Reputation points
2021-11-05T17:33:36.437+00:00

We need a tool to perform copying folders and files. There are two requests:

  1. Define Date: only copy Folder and Files are created after defining date. So we use XCOPY /D: mm-dd-yyyy
  2. Filter out certain file types and folders. So we can use XCOPY /Exclude: filter.txt (filter.txt define filter list).

we use XCopy command to create a batch (~.bat) file. It seems that XCopy works either with filter on date (/D: mm-dd-yyyy) or filter on file type (/Exclude: filter.txt) and NOT work for both together. when XCopy sourcepath destinationpath /D: 11-1-2021 and /Exclude: filter.txt, it only works for filtering file types. Defined date does not apply. It also copies folders and files which are created before "11-1-2021".

 XCOPY /S /I /E /D:11-01-2021 /EXCLUDE:get_instrument_files_omit.txt "Instrument Runs\" "xxx\Instrument Runs" 

Could we perform XCOPY and by applying both date and files filter together?

we also try XCOPY with following two steps:

  1. first filter files and folder which includes a huge data and copy folders and files into "TempRuns" folder.
  2. second apply date filter in "TempRuns" and copying to destination folder. set TEMPRUNSFOLDER="TempRuns" XCOPY /S /I /E "Instrument Runs*.*" %TEMPRUNSFOLDER% /EXCLUDE:get_instrument_files_omit.txt XCOPY /S /I /E /D:11-01-2021 %TEMPRUNSFOLDER% "xxx\Instrument Runs"

the problem with first step: during first XCOPY copying, all folder are create with date which is today. so second copy with date filter does not work and it copies all folders and files under "TempRuns" folder.

Is it possible that when first XCOPY to TempRuns folder and keep all created folders as original date?

if not, do we have other choice? we just need a simple tool. Thx!

Windows for business | Windows Client for IT Pros | User experience | Other
0 comments No comments

1 answer

Sort by: Most helpful
  1. MotoX80 37,861 Reputation points
    2021-11-05T22:02:54.027+00:00

    Robocopy would be my first choice. It has a ton of options. Here are some ones related to file age and exclusions.

    /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).
    
    
     /XF file [file]... :: eXclude Files matching given names/paths/wildcards.
     /XD dirs [dirs]... :: eXclude Directories matching given names/paths.
    

    For full help run.

    robocopy.exe /?
    

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.