0
ネストされた辞書に基づいて特定のファイルタイプを新しいディレクトリに移動しようとしています。がshutil.move(os.path.join(root,files), os.path.join(destinationpath,files))
与えファイルタイプを辞書に基づいて新しいディレクトリに移動する
001__=d5
OTHERMEDIA #move files to here
IMAGES
[mix of mediafiles in subdirectories] #move files from here
002__=alpha9
OTHERMEDIA #move files to here
IMAGES
[mix of mediafiles in subdirectories] #move files from here
コード:
は、たとえばについては、(別々のビデオや写真ファイルには)それぞれのフォルダ内の各カメラモデルのためOTHERMEDIA
にconfig[key1][other_file]
で定義されたメディアファイルを移動します。私が間違っていることは何ですか?
import shutil
import os
config = {
'd5': {},
'alpha9': {},
'g7': {},
}
config['d5']['other_file'] = ('avi', 'AVI')
config['alpha9']['other_file'] = ('jpg', 'JPG')
config['g7']['other_file'] = ('mp4', 'MP4')
destinationpath = 'OTHERMEDIA'
root = os.getcwd()
for camID in config:
for dir in next(os.walk(root))[1]:
if dir.endswith(camID):
for path, dirs, files in os.walk(os.path.join(root, dir)):
for f in files:
if any([f.lower().endswith(x) for x in config[camID]["other_file"]]):
os.path.join(path, f). files, os.path.join(destinationpath,files)
が推奨通りに更新されました(OPを参照)。エラー: 'line 20、in os.path.join(path、f)。ファイル、os.path.join(destinationpath、files) AttributeError: 'str'オブジェクトに 'files'という属性がありません。 –
HakariDo
そこに構文エラーがあります。最後の行に 'shutil.move(os.path.join(root、f)、os.path.join(destinationpath、f))'と書いておきます。 –
最終行を 'shutil.move(os.path.join(root、f)、os.path.join(destinationpath、f))'とします。エラーメッセージ: '\ Program \ Python \ Python36 \ lib \ shutil.py'および他の多くのエラー – HakariDo