0

I want to rename all file in a specified folder ending with .txt to .csv that are older then 1 day. I have the following that will get me all files ending with .txt and rename them to .csv

For /R %1 %%G IN (*.txt) DO ren "%%G" "%%~nG.csv"

The part I am struggling with is only renaming the files that are older then a day. I am looking for a solution that will work despite the date format that may be set up on a system.

Thanks

1

1 Answer 1

1

You can use forfiles, which is a native command since Windows Vista.

Forfiles

Selects and executes a command on a file or set of files. This command is useful for batch processing.

Parameters

/p <Path>
Specifies the path from which to start the search. By default, searching starts in the current working directory.

/m <SearchMask>
Searches files according to the specified search mask. The default search mask is *.*.

/s
Instructs the forfiles command to search into subdirectories recursively.

/c "<Command>"

Runs the specified command on each file. Command strings should be enclosed in quotation marks. The default command is "cmd /c echo @file".

/d [{+|-}][{<Date>|<Days>}]

Selects files with a last modified date within the specified time frame.

Source: Forfiles

Example usage

for /f "delims=" %%G in (
'forfiles /p %1 /m *.txt /s /c "cmd /c echo @path" /d -1'
) do ren "%%~G" "%%~nG.csv"

Further reading

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .