- 1 year ago
Is there a way to mass rearrange parts of a file name for many files in Windows Command Prompt?
Comment
1 / 1
Yes, you can use Windows Command Prompt to mass rearrange parts of a file name for many files. Here's an example of how to do it:
- Open Command Prompt and navigate to the directory containing the files you want to rename.
- Use the
ren
command followed by the current file name and the new file name. In the new file name, you can rearrange parts of the name by using variables enclosed in%
symbols. For example,%~dpnxf
represents the drive, path, name, and extension of the file. - You can use additional commands to further manipulate the file names, such as
set
to assign values to variables andfor
to loop through the files in the directory.
Here's an example command that would add the date and time to the beginning of each file name:
perlfor %a in (*.txt) do ren "%a" "%date:/=-%_%time::=-%_%~na%~xa"
This command loops through each .txt
file in the directory, assigns the current file name to %a
, and uses the ren
command to rename the file. The new file name begins with the current date and time, formatted to replace slashes and colons with dashes and underscores, respectively, and ends with the original file name and extension.