Renaming files in Windows explorer is easy but when you need to rename many files it can become quite tedious. A command prompt (terminal) makes it easier.
In order to rename any file you need to cd
into your folder directory and then just type one of these: ex,
Desktop> ren "My file" "Your file"
Desktop> rename "hello.txt" "goodbye.txt"
Desktop> ren "why.txt" "because.docx"
and click the Enter button
Renaming 1 file in cmd is very easy:
In this example we have a sample1.txt
and we want to change its name to sample2.txt
:
in command prompt type:
c:\temp> ren sample1.txt sample2.txt [enter]
Let's say the filename is sample1-some-unwanted-text-1234.txt
and we want to change it to sample1.txt
:
in command prompt, type:
c:\temp> ren sample1-some-unwanted-text-1234.txt sample1.txt
Renaming 1 file by replacing multiple unwanted characters using a star:
Let's say the filename is sample1-some-unwanted-text-1234.txt
and we want to change it to sample1.txt
without having to type the whole filename:
in command prompt:
c:\temp> ren sample1*.txt sample1.txt
This * basically means any characters inbetween sample1
and .txt
will be replaced.
Renaming multiple files with similar names
If you want to rename multiple files, i.e. sample1 2020-08-01.txt
, sample2 2020-08-05.txt
, sample3 2020-08-10.txt
,sample4 2020-08-13.txt
, you want to keep the first 7 characters you want to get rid of the dates:
in command prompt:
c:\temp> ren sample?*.txt sample?.txt
In this example, you want to keep the word sample
and the number X (where X can be any number or character). Using a ? will leave the number in place and * instructs the rename-command to replace any characters in between sampleX
and .txt
Warning: It happens very quickly that a command prompt rename operation renames too many files and you can't undo it. So, when renaming multiple files it is advisable to make a copy of all the files you want to rename, put them in a temp folder, then run your rename commands in the temp folder, and when you're certain that it works, go back and rename the original files.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With