简体   繁体   English

如何重命名 Windows CMD 中的文件(命令提示符)

[英]How to rename files in Windows CMD (command prompt)

Renaming files in Windows explorer is easy but when you need to rename many files it can become quite tedious.在 Windows 资源管理器中重命名文件很容易,但是当您需要重命名许多文件时,它会变得相当乏味。 A command prompt (terminal) makes it easier.命令提示符(终端)使它更容易。

Renaming 1 file in cmd is very easy:重命名 cmd 中的 1 个文件非常简单:
In this example we have a sample1.txt and we want to change its name to sample2.txt :在此示例中,我们有一个sample1.txt ,我们想将其名称更改为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 :假设文件名是sample1-some-unwanted-text-1234.txt ,我们想将其更改为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 :通过使用星号替换多个不需要的字符来重命名 1 个文件
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:假设文件名是sample1-some-unwanted-text-1234.txt ,我们想将其更改为sample1.txt而无需输入整个文件名:

    in command prompt:
    c:\temp> ren sample1*.txt sample1.txt

This * basically means any characters inbetween sample1 and .txt will be replaced.这个 * 基本上意味着sample1.txt之间的任何字符都将被替换。

Renaming multiple files with similar names重命名具有相似名称的多个文件
If you want to rename multiple files, ie 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:如果要重命名多个文件,即sample1 2020-08-01.txtsample2 2020-08-05.txtsample3 2020-08-10.txtsample4 2020-08-13.txt 2020-08-13.txt ,则要保留您要删除日期的前 7 个字符:

    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).在此示例中,您希望保留单词sample和数字 X(其中 X 可以是任何数字或字符)。 Using a?用一个? will leave the number in place and * instructs the rename-command to replace any characters in between sampleX and .txt将保留数字并 * 指示重命名命令替换sampleX.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.因此,当重命名多个文件时,建议复制所有要重命名的文件,将它们放在临时文件夹中,然后在临时文件夹中运行重命名命令,当您确定它有效时,go返回并重命名原始文件。

in order to rename any folder you need to cd to your folder directory and then just type one of thes: ex,为了重命名任何文件夹,您需要 cd 到您的文件夹目录,然后只需键入其中一个:例如,

  • Desktop>ren "My file" "Your file"桌面>ren "我的文件" "你的文件"
  • Desktop> rename "hello.txt" "goodbye.txt"桌面>重命名“hello.txt”“goodbye.txt”
  • Desktop> ren "why.txt" "because.docx" and click the Enter button桌面> ren "why.txt" "because.docx" 并点击 Enter 按钮

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM