Wednesday, November 24, 2010

How to use Windows batch script to rename multiple files


@echo off

FOR %%F IN (*.wav) DO (
FOR /F "tokens=1-5 delims=/: " %%J IN ("%%~tF") DO (
rename %%F %%L%%K%%J%%M%%N_%%~nF%%~xF
)
)


which renames all the files matching *.wav, and the new files are began with the year (%%L), the month (%%K), the day (%%J), the hour (%%M), and the minute (%%N) according to the file's creation time.

Here I also point out how to extract the file name without file extension (%%~nF), file extension (%%~xF) and file creation time (%%~tF).

For example, this batch file can rename 1.wav and aaa.wav as 201011240600_1.wav and 201011230630_aaa.wav, respectively.

No comments: