Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
198 views
Welcome To Ask or Share your Answers For Others

1 Answer

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:	emp> 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:	emp> 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:	emp> 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:	emp> 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...