我有一个Python脚本,它会查找文件夹中所有文件中特定的单词,并将该单词替换为空格。我希望在不更改要查找的单词的情况下,继续添加新的单词供脚本查找并执行相同的替换操作。
我在macOS El Capitan上运行此脚本。下面是该脚本:
我在macOS El Capitan上运行此脚本。下面是该脚本:
import os
paths = (os.path.join(root, filename)
for root, _, filenames in os.walk('/Users/Test/Desktop/Test')
for filename in filenames)
for path in paths:
# the '#' in the example below will be replaced by the '-' in the filenames in the directory
newname = path.replace('.File',' ')
if newname != path:
os.rename(path, newname)
for path in paths:
# the '#' in the example below will be replaced by the '-' in the filenames in the directory
newname = path.replace('Generic',' ')
if newname != path:
os.rename(path, newname)
能够提供给这个新手的任何帮助都将不胜感激。