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.