現在、フォルダー/ファイル名から特殊文字と余分なデータを削除しながら、オブジェクトの名前を保持してダウンロードフォルダーをクリーンアップするスクリプトを作成して、python を学習しようとしています。
すなわち:
../Completed Downloads/random.download.here.x264.team
../Completed Download/random download here
としても
file.name.randomstring_randomstring.mkv
file name randomstring randomstring (date).mkv
しばらく探していましたが、これらのファイルを確認するスクリプトを作成することはできますが、個々の特殊文字を取り出して名前を変更するだけのスクリプトを作成することはできないようです. すると、次のようになります。
Traceback (most recent call last):
File "C:\Python27\Scripts\plexprep.py", line 7, in <module>
os.rename(dir, dir.replace(".", "").lower())
WindowsError: [Error 2] The system cannot find the file specified
これが私のスクリプトの始まりです:
import fnmatch
import os
#Matches directories for Plex and renames directories to help Plex crawl.
for dir in os.listdir('F:\Downloads\Completed Downloads'):
if fnmatch.fnmatch(dir, '*'):
os.rename(dir, dir.replace(".", "").lower())
#Matches filenames for Plex and renames files/subdirectories to help Plex crawl.