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

Jane Jie Chen 346 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 10
Windows 10
A Microsoft operating system that runs on personal computers and tablets.
10,601 questions
Windows
Windows
A family of Microsoft operating systems that run across personal computers, tablets, laptops, phones, internet of things devices, self-contained mixed reality headsets, large collaboration screens, and other devices.
4,739 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. MotoX80 31,571 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 /?
    
    0 comments No comments