Sho*_*ban 39 windows file-io batch-rename
有没有办法在子目录中批量重命名文件?
例:
在具有目录和子目录的文件夹中将*.html重命名为*.htm.
Ano*_*ous 75
Windows命令提示符:(如果在批处理文件中,将%x更改为%% x)
for /r %x in (*.html) do ren "%x" *.htm
Run Code Online (Sandbox Code Playgroud)
这也适用于重命名文件的中间部分
for /r %x in (website*.html) do ren "%x" site*.htm
Run Code Online (Sandbox Code Playgroud)
对于Windows,这是我发现的最好的工具:
它可以做任何事情,并有厨房水槽.
对于Linux,您可以使用大量的脚本语言和shell来帮助您,就像之前的答案一样.
find . -regex ".*html$" | while read line;
do
A=`basename ${line} | sed 's/html$/htm/g'`;
B=`dirname ${line}`;
mv ${line} "${B}/${A}";
done
Run Code Online (Sandbox Code Playgroud)
小智 6
如果你有 forfiles(我认为它是 Windows XP 和 2003 以及更新的东西附带的),你可以运行:
forfiles /S /M *.HTM /C "cmd /c ren @file *.HTML"
Run Code Online (Sandbox Code Playgroud)
在 Bash 中,您可以执行以下操作:
for x in $(find . -name \*.html); do
mv $x $(echo "$x" | sed 's/\.html$/.htm/')
done
Run Code Online (Sandbox Code Playgroud)
在python中
import os
target_dir = "."
for path, dirs, files in os.walk(target_dir):
for file in files:
filename, ext = os.path.splitext(file)
new_file = filename + ".htm"
if ext == '.html':
old_filepath = os.path.join(path, file)
new_filepath = os.path.join(path, new_file)
os.rename(old_filepath, new_filepath)
Run Code Online (Sandbox Code Playgroud)