如何在Windows CMD中重命名文件(命令提示符) [英] How to rename files in Windows CMD (command prompt)

查看:2072
本文介绍了如何在Windows CMD中重命名文件(命令提示符)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Windows资源管理器中重命名文件很容易,但是当您需要重命名许多文件时,它会变得很繁琐。

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.

推荐答案

在cmd中重命名1个文件非常容易:

在此示例中,我们有一个 sample1.txt ,我们想要将其名称更改为 sample2.txt

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]

假设文件名是 sample1-some- preferred-text-1234.txt ,我们想将其更改为 sample1.txt

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

通过替换多个不需要的文件来重命名1个文件使用星号的字符

假设文件名是 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

这*基本上表示任何字符在<$ c之间$ c> sample1 和 .txt 将被替换。

This * basically means any characters inbetween sample1 and .txt will be replaced.

重命名具有相似内容的多个文件名称

如果要重命名多个文件,即 sample1 2020-08-01.txt sample2 2020-08-05.txt sample3 2020-08-10.txt sample4 2020-08-13 .txt ,要保留要删除日期的前7个字符:

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

在此示例中,您要保留单词 sample 和数字X(其中X可以是任何数字或字符)。用一个 ?将保留该数字,并*指示重命名命令替换 sampleX .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

警告:很快,命令提示符重命名操作会重命名太多文件,您无法撤消它。因此,在重命名多个文件时,建议对要重命名的所有文件进行复制,将它们放在temp文件夹中,然后在temp文件夹中运行重命名命令,然后在确定可以工作时,转到返回并重命名原始文件。

这篇关于如何在Windows CMD中重命名文件(命令提示符)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆