特定の単語のフォルダ内のすべてのファイルを調べ、その単語をスペースで置き換えるpythonスクリプトがあります。スクリプトを実行するたびに見えるように言葉を変更するのではなく、スクリプトの新しい単語を追加して、同じ置換アクションを探して実行したいと考えています。文字を削除してファイル名を置換するPythonスクリプト
私はこれを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)
あなたはこの初心者に提供できるヘルプがあります。
ああ、私はちょうど私の前に答えを見ました、私はそれがはるかに効率的な一度だけファイル名を編集する方法が好きです。私はあなたが彼らの答えを使用することをお勧めしますが、私はこの代替アイデアが有用であると思ったら私を残しておきます。 –