如何创建批处理文件来重命名文件夹中的大量文件?
我想重命名 WinXP 系统上文件夹中的大量文件,最好使用批处理文件。
这些文件目前的命名方式如下:
假期2010 001.jpg
假期2010 002.jpg
假期2010 003.jpg
我想将它们更改为:
十二月001.jpg
十二月002.jpg
十二月003.jpg
我该如何执行此操作?
I'd like to rename a large number of files within a folder on a WinXP system, preferably using a batch file.
The files are currently named like this:
Vacation2010 001.jpg
Vacation2010 002.jpg
Vacation2010 003.jpg
And I'd like to change them to:
December 001.jpg
December 002.jpg
December 003.jpg
How can I perform this operation??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
其作用是循环遍历批处理文件所在文件夹中的所有 .jpg 文件,并将文件名中的 Vacation2010 替换为 December。
What this does is it loops over all .jpg files in the folder where the batch file is located and replaces the Vacation2010 with December inside the filenames.
这将为您提供诸如以下的行:
在您最喜欢的 Windows 中编辑 file.bat 文本编辑器,相当于:
这是一个 正则表达式;许多编辑器都支持它们,但 Windows 中没有一个默认支持它们(据我所知)。您还可以获得命令行工具,例如 sed 或 perl,在转义命令行后,它们可以采用我上面的确切语法。
结果行将如下所示:
您可能会将这些行识别为重命名命令,原始列表中的每个文件一个。 ;) 在 cmd.exe 中运行该批处理文件。
This will give you lines such as:
Edit file.bat in your favorite Windows text-editor, doing the equivalent of:
That's a regex; many editors support them, but none that come default with Windows (as far as I know). You can also get a command line tool such as sed or perl which can take the exact syntax I have above, after escaping for the command line.
The resulting lines will look like:
You may recognize these lines as rename commands, one per file from the original listing. ;) Run that batch file in cmd.exe.
您可以轻松完成此操作,无需手动编辑或使用精美的文本编辑器。这是一个 vb 脚本。
另存为 myscript.vbs 并
you can do this easily without manual editing or using fancy text editors. Here's a vbscript.
save as myscript.vbs and
此脚本允许您更改包含具有相同名称的
Vacation2010
的所有文件的名称,但使用December
而不是Vacation2010
。如果复制并粘贴代码,则必须将
.bat
保存在照片的同一文件夹中。如果您想将脚本保存在另一个目录中 [例如,您有一个最喜欢的实用程序文件夹],您必须使用照片的路径更改
_dir
的值。如果您必须对其他照片 [或其他文件更改
_ext
] 执行相同的工作,则必须使用要更改的字符串更改_toEdit
的值 [或删除] 和_with
的值以及您想要代替_toEdit
的字符串 [SET "_with="
如果您只是想删除在_toEdit
中指定的字符串]。This script allows you to change the name of all the files that contain
Vacation2010
with the same name, but withDecember
instead ofVacation2010
.If you copy and paste the code, you have to save the
.bat
in the same folder of the photos.If you want to save the script in another directory [E.G. you have a favorite folder for the utilities] you have to change the value of
_dir
with the path of the photos.If you have to do the same work for other photos [or others files changig
_ext
] you have to change the value of_toEdit
with the string you want to change [or erase] and the value of_with
with the string you want to put instead of_toEdit
[SET "_with="
if you simply want to erase the string specified in_toEdit
].您不需要批处理文件,只需从 powershell 执行此操作:
You don't need a batch file, just do this from powershell :