ren (更改文件和目录的名称)

舞夕之 发表于 2020-06-28 14:08
浏览次数:
在手机上阅读

REN和RENAME命令可更改文件和目录的名称。

在MS-DOS的早期版本中,您需要使用MOVE命令来重命名目录或文件,而不是使用REN或RENAME。

In earlier releases of MS-DOS, instead of using ren or rename you need to use the move command to rename directories or files.

查看英文版

目录

1 ren 运行系统环境

2 ren and rename 语法

3 ren and rename 示例(一)

4 ren and rename 示例(二)

ren 运行系统环境

Windows 95

Windows 98

Windows xp

Windows vista

Windows 2000

Windows 7

Windows 8

Windows 10

Windows NT

Windows ME

All Versions of MS-DOS

ren and rename 语法

重命名文件/目录或文件/目录。

RENAME [drive:][path][directoryname1 | file name 1] [directory name 2 | file name 2]
REN [drive:][path][directoryname1 | file name 1] [directory name 2 | file name 2]

Renames a file/directory or files/directories.

RENAME [drive:][path][directoryname1 | file name 1] [directory name 2 | file name 2]
REN [drive:][path][directoryname1 | file name 1] [directory name 2 | file name 2]

不能为重命名文件的目标指定新的驱动器或路径。

You cannot specify a new drive or path for the destination of a renamed file.

查看英文版

查看中文版

ren and rename 示例(一)

rename c:\computer hope

将目录“computer”的名称更改为“Hope”。

rename *.txt *.bak

将文件扩展名为“.txt”的所有文本文件重命名为扩展名为“.bak”的文件。

警告:

使用星号(*)重命名文件时,请记住可以重命名目录中的所有文件。如果当前目录中存在不希望重命名的文件,请确保通过添加文件扩展名来减少重命名的重复性。

rename * 1_*

重命名所有文件以1开头。上面命令中的星号(*)是通配符的示例,可以表示一个或多个字符。只有星号时,当前目录中的所有文件名都将重命名为前两个字符为“1”。

提示:

若要仅表示或匹配一个字符,请改用问号(?)字符。

注意:
该命令不会在文件名的前面添加或添加文本; 它替换当前目录中每个文件的前两个字符。 例如,如果有一个文件名为hope.txt,它将被重命名为1_pe.txt。
rename "computer hope.txt" "example file.txt"

将文件“ computer hope.txt”重命名为“ example file.txt”。 处理带有空格的文件或目录时,必须用引号将其引起来。 否则,您将收到一条错误消息,指出获取“命令的语法不正确。”错误。

rename c:\computer hope

Change the name of the directory "computer" to "hope."

rename *.txt *.bak

Rename all text files with the ".txt" file extension to files with ".bak" extension.

Warning:

When renaming files using an asterisk (*) keep in mind that you can rename all files in a directory. If there are file in the current directory you do not want renamed be sure to make your rename less greedy by adding a file extension.

rename * 1_*

Rename all files to begin with 1_. The asterisk (*) in the command above is an example of a wild character and can represent one or more characters. With only an asterisk, all file names in the current directoryare renamed to have "1_" as the first two characters.

Tip:

To represent or match one single character only, use the question mark (?) character instead.

Note:

This command doesn't append or add text to the front of the file name; it replaces the first two characters of every file in the current directory. For example, if there was a file were named hope.txt, it would be renamed to 1_pe.txt.

rename "computer hope.txt" "example file.txt"

Rename the file "computer hope.txt" to "example file.txt". When you are dealing with a file or directory with a space, it must be surrounded byquotes. Otherwise, you'll get an error indicating that Getting "The syntax of the command is incorrect." error."

查看英文版

查看中文版

ren and rename 示例(二)

获取“命令的语法不正确。”错误

在Windows命令行中,当尝试使用空格复制,移动或重命名文件或目录时,您可能会看到“命令的语法不正确”。 错误信息。 当Windows命令行由于格式不正确而无法理解该命令的语法时,会生成此错误消息。 要解决此问题,请在文件名或目录名中用引号引起来。

例如,如果我们有一个名为“ computer hope”的目录或文件名,则应输入以下命令。

复制带有空格的文件

在第一个示例中,我们将文件“ computer hope.txt”复制到Hope目录中。 如果文件中没有引号,则会显示“命令的语法不正确”。 错误信息。

copy "computer hope.txt" hope
移动文件名中带有空格的文件

接下来,以下命令会将文件“ computer hope.txt”移至希望目录。 同样,没有引号,您会收到错误消息。

move "computer hope.txt" hope
重命名文件名称中带有空格的文件

最后,以下命令会将同一文件重命名为示例file.txt,该文件名中也包含空格.

rename "computer hope.txt" "example file.txt"

Getting "The syntax of the command is incorrect." error

In the Windows command line, when trying to copy, move, or rename a file or directory with a space you may get the "The syntax of the command is incorrect." error message. This error message is generated when the Windows command line does not understand the syntax of the command because it is not formatted properly. To resolve this issue, surround any file name or directory name with spaces in it with quotes.

For example, if we had a directory or file name called "computer hope" you would enter the following commands.

Copying a file with a space

In this first example, we're copying the file "computer hope.txt" into the hope directory. Without the quotes around the file, you get "The syntax of the command is incorrect." error message.

copy "computer hope.txt" hope
Moving a file with a space in the file name

Next, the following command would move the file "computer hope.txt" into the hope directory. Again, without quotes you get the error message.

move "computer hope.txt" hope
Renaming a file with a space in the file name

Finally, the following command would rename the same file to example file.txt, which also has a space in the file name.

rename "computer hope.txt" "example file.txt"

查看英文版

查看中文版

其他命令行

reg | rd/rmdir | robocopy | route | runas |

如此好文,分享给朋友
发表评论
验证码:
评论列表
共0条