Skip to main content
formatting
Source Link
Ben N
  • 41.3k
  • 17
  • 147
  • 191

for /f "delims=:" %f in ('dir *.txt /O:D /T:W /B') do @echo %f

for /f "delims=:" %f in ('dir *.txt /O:D /T:W /B') do @echo %f

This command will use the DIR commanddir to sort by oldest to newest date /O:D(/O:D) using the last written date /T:W(/T:W) and bare format /B(/B) to just return the filenames. Setting the delimsdelims to :: in the FORfor command keeps it from trying to parse the filename based on spaces or commas since :: is not allowed in a filename.

for /f "delims=:" %f in ('dir *.txt /O:D /T:W /B') do @echo %f

will use the DIR command to sort by oldest to newest date /O:D using the last written date /T:W and bare format /B to just return the filenames. Setting the delims to : in the FOR command keeps it from trying to parse the filename based on spaces or commas since : is not allowed in a filename.

for /f "delims=:" %f in ('dir *.txt /O:D /T:W /B') do @echo %f

This command will use dir to sort by oldest to newest date (/O:D) using the last written date (/T:W) and bare format (/B) to just return the filenames. Setting the delims to : in the for command keeps it from trying to parse the filename based on spaces or commas since : is not allowed in a filename.

Source Link

for /f "delims=:" %f in ('dir *.txt /O:D /T:W /B') do @echo %f

will use the DIR command to sort by oldest to newest date /O:D using the last written date /T:W and bare format /B to just return the filenames. Setting the delims to : in the FOR command keeps it from trying to parse the filename based on spaces or commas since : is not allowed in a filename.