スクリプトは、ルートパスディレクトリを再帰的に通過し、* .mp4拡張子のすべてのファイルを見つける必要があります。ディレクトリ構造を持つファイルのリストを出力します。次に、ファイルをdestDirディレクトリに移動します。私が実行している問題は、ファイルを新しいディレクトリに移動しようとするときです。 rootPathディレクトリのファイルのみが新しい宛先に移動されます。 ROOTPATH下のサブディレクトリにあるファイルのエラーが発生します。Pythonの再帰的なファイル検索と1つのコピー先ディレクトリへの移動
/Volumes/VoigtKampff/Temp/TEST/level01_test.mp4
/Volumes/VoigtKampff/Temp/TEST/Destination/2levelstest02.mp4
Traceback (most recent call last):
File "/Volumes/HomeFolders/idmo04/Desktop/ScriptsLibrary/Python/recursive_find.py", line 14, in <module>
shutil.move(root+filename, destDir+'/'+filename)
File "/Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/shutil.py", line 281, in move
copy2(src, real_dst)
File "/Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/shutil.py", line 110, in copy2
copyfile(src, dst)
File "/Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/shutil.py", line 65, in copyfile
with open(src, 'rb') as fsrc:
IOError: [Errno 2] No such file or directory: '/Volumes/VoigtKampff/Temp/TEST/Destination2levelstest02.mp4'
##############ここではスクリプトです
import fnmatch
import os
import shutil
rootPath = '/Volumes/VoigtKampff/Temp/TEST/'
destDir = '/Volumes/VoigtKampff/Temp/TEST2/'
matches = []
for root, dirnames, filenames in os.walk(rootPath):
for filename in fnmatch.filter(filenames, '*.mp4'):
matches.append(os.path.join(root, filename))
print(os.path.join(root, filename))
shutil.move(root+filename, destDir+'/'+filename)
そこに - 私は約束する – JRM