-1

I'm referring to a batch script to create a list of files having file timestamp greater than specified date and store the list of pathnames in a text file. I want to use this to feed a process that needs to consume the files chronologically.

During my search, I came across this site that states

xcopy \rawdata \reports /d:12-29-1993 /l > xcopy.out

"The file Xcopy.out lists every file that is to be copied."

Since, the content is no longer updated/supported, I want to know the default order in which the pathnames would be listed in my text file or if I can sort the pathnames myself before copying.

I do get a sorted filelist using the below but I need to confirm it will be so on every run as I have not mentioned any sort order explicitly (I don't know how to).

xcopy (source_dir) /l /s /d:(specified_date) .<myfileList.txt

I also want to know what the dot after specified date does.

So far, I have this information (from the same site):

when used with xcopy:
/l - Generates a list of files, does not actively copy them.
/s - Copies non-empty directories and subdirectories.
/d [:MM-DD-YYYY] - Copies source files changed on or after the specified date only. If not specified, copies all source files that are newer than existing destination files.

Any help is greatly appreciated.

4
  • The order is going to be alphabetical by filename, not date.. Commented Oct 19, 2023 at 15:00
  • My assumption is that the 'dot' is simply a reference to the current directory as the destination. Even though the /l option is being used a destination directory is still part of the required syntax. Although I'm more confused about why it is using <myfileList.txt and not >myfileList.txt. Commented Oct 19, 2023 at 15:02
  • 1
    The sequence would be alphabetic filenames followed by subdirectorynames in alphabetic order IF the source file system is NTFS and random if the source file system is FAT(32) Commented Oct 19, 2023 at 16:41
  • You can solve this problem in batch, however. If you process the output of xcopy /L /Y (the /Y proceeds without need fo keyboard), which is a filename list (except for the last line) and ask for the file timestamp using %%~t? and then process the timestamp to yyyymmddhhmmss format (which has been done many times on SO) , produce a tempfile as lines of yy…ss filename, sort it and process the result. Commented Oct 19, 2023 at 18:34

1 Answer 1

0

This is one possible answer if you’re willing to change the date format on your system. You can use 'For', 'FORFILES' and 'Sort' to build a list of files.

This solution will sort files by date independent of their sub-directories.

  1. Change your date format to something more easily sortable, chronologically:

Control Panel -> Region -> Additional Settings… -> Date(tab) -> Short Date = “yyyy-MM-dd”

enter image description here

  1. Execute this command to output list of files modified since 2023-04-01, %a=Date %b=Full Filename This example is targeting the \Temp\ directory.

C:\Temp>For /F "tokens=1,2 delims=^"^" %a in ('"FORFILES /P "C:\Temp" /S /D 2023-04-01 /C "cmd /c @echo @fdate @file" | sort"') do @echo %a %b

You can replace the "@echo" command at the end with another command using %b as the filename.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.