question

JaneJieChen-2183 avatar image
0 Votes"
JaneJieChen-2183 asked MotoX80 answered

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

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-generalwindows-7
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

MotoX80 avatar image
0 Votes"
MotoX80 answered

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 /?

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.