If you want to delete the original files we just need to run the command for %%F in ("C:\test\*.txt") do ( del %%F ). You can use the command set "ParsedDate=!MDate:~6,4!!MDate:~0,2!!MDate:~3,2!" to convert the output of set "MDate=%%~tF" from MM/DD/YYYY hh:mm to YYYYMMDD.Īfter that we can copy the files to new files using the value of %ParsedDate% in the filename. To parse the date that is provided by set "MDate=%%~tF" you will need to specify which parts of the value stored by %MDate% you want to use in the output. To get the modify date of a file we can use set "MDate=%%~tF".
You were very close, but you were missing a few things.
Here is the code you need to use to iterate the text files, obtain the modified date of each file, copy each file using the modified date as part of the file name, and delete the original files.