そこで、選択したMusicフォルダーを調べて、特定のアルバムにアルバムカバーがないかどうかをユーザーに通知するPythonスクリプトを作成しようとしています。基本的にすべてのファイルを調べてチェックif file[-4:] in (".jpg",".bmp",".png")
し、trueの場合は画像ファイルを見つけました。明確にするために、私のフォルダの構造は次のとおりです。
- 音楽フォルダ
- アークティック・モンキーズ
- ハンバグ(2009)
- 吸って見て(2011)
- モルヒネ
- 痛みの治療(1993)
- アークティック・モンキーズ
.. 等々。スクリプトをテストして、Arctic Monkeysディレクトリにカバーがないかどうかを確認しています。スクリプトは、「Humbug(2009)」フォルダを調べて、コマンドプロンプトに表示されないAlbumArtSmall.jpgを見つけたので、試してみました。 「隠しファイル/フォルダを表示する」とまだ何もありません。ただし、「保護されたオペレーティングシステムファイルを非表示にする」のチェックを外すとファイルが表示されるので、ちょっと変です。
私の質問は-非表示/保護されたファイルの検索をスキップするようにPythonに指示するにはどうすればよいですか?os.listdir()を使用して隠しファイルを無視する方法 を確認しましたか?しかし、そこで見つけた解決策は、「。」で始まるファイルに対してのみ機能し、それは私が必要としているものではありません。
乾杯!
編集-コードは次のとおりです。
import os
def findCover(path, band, album):
print os.path.join(path, band, album)
coverFound = False
for mFile in os.listdir(os.path.join(path, band, album)):
if mFile[-4:] in (".jpg",".bmp",".png"):
print "Cover file found - %s." % mFile
coverFound = True
return coverFound
musicFolder = "E:\Music" #for example
noCovers = []
for band in os.listdir(musicFolder): #iterate over bands inside the music folder
if band[0:] == "Arctic Monkeys": #only Arctic Monkeys
print band
bandFolder = os.path.join(musicFolder, band)
for album in os.listdir(bandFolder):
if os.path.isdir(os.path.join(bandFolder,album)):
if findCover(musicFolder, band, album): #if cover found
pass #do nothing
else:
print "Cover not found"
noCovers.append(band+" - "+album) #append to list
else: #if bandFolder is not actually a folder
pass
print ""