有没有办法对子目录下的文件进行批量重命名?
例如:
在包含目录和子目录的文件夹中,将*.html重命名为*.htm。
发布于 2008-10-29 05:14:39
Windows命令提示符:(如果在批处理文件中,请将%x更改为%%x)
for /r %x in (*.html) do ren "%x" *.htm这也适用于重命名文件的中间位置
for /r %x in (website*.html) do ren "%x" site*.htm发布于 2008-10-29 05:15:11
find . -regex ".*html$" | while read line;
do
A=`basename ${line} | sed 's/html$/htm/g'`;
B=`dirname ${line}`;
mv ${line} "${B}/${A}";
done发布于 2008-10-29 05:17:28
在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)https://stackoverflow.com/questions/245840
复制相似问题