您是否需要在
Windows中一次重命名多个文件?手动完成可能是一项艰巨的任务,但Windows支持您可以运行的脚本来自动执行重命名过程,从而节省大量时间。
例如,考虑上面示例图像中的情况,您有一个包含数百个图像的文件夹,每个图像都命名为Copy of,然后是一个或两个单词,例如Copy of Black Tea.jpg。
您可以运行一个脚本来为您完成所有重命名,而不是手动重命名每个文件以删除“副本”或将这些单词更改为其他内容。
软件(Software)程序和相机通常会在导出的文件中附加一组特定的字符,因此该脚本在这些情况下会派上用场。
如何制作重命名脚本(How to Make the Renaming Script)
脚本本质上是一组精心设计的命令,用于准确告诉计算机要做什么。这是我们正在处理的“查找和替换”脚本:
Set objFso = CreateObject(“Scripting.FileSystemObject”)
Set Folder = objFSO.GetFolder(“ENTER\PATH\HERE”)
对于 Folder.Files 中的每个文件(For Each File In Folder.Files)
sNewFile = File.Name
sNewFile = Replace(sNewFile,”ORIGINAL”,”REPLACEMENT”)
if (sNewFile<>File.Name) then
File.Move(File.ParentFolder+”\”+sNewFile)
万一( end if)
下一个(Next)
要使用这个脚本需要一个文本编辑器。
Notepad,内置于Windows,就可以了。
第一步(Step 1):打开记事本(Notepad)。您可以通过在开始(Start)菜单中搜索记事本(Notepad)或在运行对话框中执行记事本
命令 ( (notepad
)WIN+R ) 来执行此操作。
第 2 步(Step 2):完全按照上面显示的方式复制脚本,并将其粘贴到记事本(Notepad)中。
第 3 步(Step 3):编辑文件重命名脚本,使其适用于您的独特情况。
为此,您需要将名为ENTER\PATH\HERE 的文本更改为您即将重命名的文件所在的确切文件夹。
例如,您可能想重命名桌面上某个文件夹中的一组文件,在这种情况下,您的文件夹路径可能如下所示:C:\Users\Matt\Desktop\Converted MP3s\。
要使脚本始终适用于它当前所在的文件夹,只需将路径更改为.\. 也就是说,一个句点,然后是一个反斜杠,没有空格。以这种方式使用脚本可以让您将其放入任何文件夹并使其仅自动应用于该文件夹。
还要将ORIGINAL更改
为您要替换的字符,并删除REPLACEMENT以便您可以输入应该替换原始字符的文本。换句话说,您可以将脚本的这一行解读为“将 THIS 替换为 THIS。(replace THIS with THIS.)”
注意:确保在您看到的每个实例中都保留引号。它们需要保留在文件夹路径和替换部分中。(Note: Make sure you keep
the quotes in every instance you see them. They need to remain in the folder
path and the replace section.)
第 4 步(Step 4):转到文件(File )>另存为(Save As)并将文件命名为您喜欢的任何名称,但请务必将“另存(Save)为类型”选项更改为All Files
(*) 并将.vbs附加到文件名的末尾。
第 5 步(Step 5):您现在可以关闭记事本(Notepad)并执行VBS文件以应用脚本。
就是这样!要编辑VBS文件以更改要重命名的文件的位置,或调整文件中要替换的内容,只需右键单击VBS文件,如上所示,但不要打开它,而是选择Edit。
如何在 Windows 10 中批量重命名文件(How
to Bulk Rename Files in Windows 10)
如果您使用的是Windows 10,则有一个易于使用的内置重命名功能,可能正是您所追求的。与上面的脚本相比,此方法是独一无二的,因为即使文件具有完全不同的文件名,它也可以工作。
换句话说,这两种方法有完全不同的用例。假设您有 100 个文件,每个文件中都包含单词house以及其他随机字符。你想保持所有的字符不变,但把房子这个词变成了家(home)。该脚本非常适合。
但是,如果这 100 个文件都被命名为随机字符,并且您希望它们像housepics一样非常相似,您可以使用Windows 10重命名功能将第一个重命名为housepics (1),第二个重命名为housepics (2),第三个到housepics (3)等等。
以下是在Windows 10中执行此操作的方法:
第 1 步(Step
1):突出显示要重命名的文件。
第 2 步(Step
2):按F2键或右键单击所选文件之一,然后选择重命名(Rename)。
第 3 步(Step
3):键入要使用的文件名,然后按Enter。
立即,每个选定的文件都将使用完全相同的文件名。如果每个文件使用不同的文件扩展名,则它们的名称将相同,但如果它们具有相同的文件扩展名,则会在末尾附加一个数字,因为两个或多个文件不能在同一文件中使用相同的文件名文件夹。
Use This Script to Rename Multiple Files at Once in Windows
Do you need to rename several files at once in
Windows? It can be quite the taѕk to do it manually, but Windows supports
sсripts that you can run to automate the renaming process, saving you loads of
time.
As an example, consider a case like in the example image above where you have a folder of hundreds of images each named Copy of and then a word or two, like Copy of Black Tea.jpg.
Instead of manually renaming each file to delete “Copy of” or to change those words to something else, you could run a script to do all the renaming for you.
Software programs and cameras often append a
specific set of characters to exported files, so this script comes in handy in
those circumstances.
How to Make the Renaming Script
A script is essentially a carefully crafted set
of commands to tell the computer exactly what to do. Here’s the “find and
replace” script we’re dealing with:
Set objFso = CreateObject(“Scripting.FileSystemObject”)
Set Folder = objFSO.GetFolder(“ENTER\PATH\HERE”)
For Each File In Folder.Files
sNewFile = File.Name
sNewFile = Replace(sNewFile,”ORIGINAL”,”REPLACEMENT”)
if (sNewFile<>File.Name) then
File.Move(File.ParentFolder+”\”+sNewFile)
end if
Next
To use this script requires a text editor.
Notepad, built-in to Windows, will do just fine.
Step 1: Open Notepad. You can
do this by searching for Notepad in the Start menu or by executing the notepad
command in the Run dialog box (WIN+R).
Step 2: Copy the script
exactly as it’s shown above, and paste it into Notepad.
Step 3: Edit the file rename script to make it apply to your unique
situation.
To do that, you need to change the text called ENTER\PATH\HERE to the exact folder where your soon-to-be-renamed files are located.
For example, maybe you want to rename a group of files in a folder on your desktop, in which case your folder path might look like this: C:\Users\Matt\Desktop\Converted MP3s\.
To make the script always apply to the folder
it’s currently located in, just change the path to .\. That is, a period and then a backslash, without a space. Using
the script this way lets you drop it into any folder and have it automatically
apply to only that folder.
Also change ORIGINAL
to the characters you want to replace, and delete REPLACEMENT so that you can enter the text that should replace the
original characters. In other words, you can read this line of the script as “replace THIS with THIS.”
Note: Make sure you keep
the quotes in every instance you see them. They need to remain in the folder
path and the replace section.
Step 4: Go to File > Save As and name the file anything you like, but be sure to change
the “Save as type” option to All Files
(*) and append .vbs to the end
of the file name.
Step 5: You can now close out of Notepad and execute the VBS file to
apply the script.
That’s it! To edit the VBS file to
change the location of the files to rename, or to adjust what to replace in the
files, just right-click the VBS file like you see above, but instead of opening
it, choose Edit.
How
to Bulk Rename Files in Windows 10
If you’re using Windows 10, there’s
a built-in renaming feature that’s easy to use and might be exactly what you’re
after. This method is unique compared to the script above because it works even
if the files have completely different filenames.
In other words, these two methods
have completely different use cases. Let’s say you have 100 files that each
have the word house in them along
with other random characters. You want to keep all the characters untouched but
make the word house into home. The
script is great for that.
However,
if the 100 files are all named random characters and you want them to be really
similar like housepics, you can use
the Windows 10 renaming function to rename the first to housepics (1), the second to housepics
(2), the third to housepics (3),
and so on.
Here’s how to do this in Windows 10:
Step
1: Highlight the files you want to
rename.
Step
2: Press the F2 key or right-click one of the selected files and choose Rename.
Step
3: Type the filename you want to use
and then press Enter.
Instantly, every selected file will
use the exact same filename. If each file is using a different file extension,
they’ll all be named identically, but if they have the same file extension, a
number will be appended to the end since two or more files can’t use the same
filename in the same folder.