So, I’m trying to make myself a Python script which goes through the selected Music folder and tells the user if specific album doesn’t have an album cover. It basically goes through all the files and checks if file[-4:] in (".jpg",".bmp",".png"), if true, it found a picture file. Just to make it clear, the structure of my folders is:
- Music folder
- Arctic Monkeys
- Humbug (2009)
- Suck it and see (2011)
- Morphine
- Cure For Pain (1993)
- Arctic Monkeys
.. and so on. I’m testing the script to find if there’s a missing cover in my Arctic Monkeys directory, and my script goes through the “Humbug (2009)” folder and finds AlbumArtSmall.jpg which doesn’t show up in the command prompt so I tried “Show hidden files/folders” and still nothing. However, the files show up once I uncheck “Hide protected operating system files”, so that’s kinda weird.
My question is – how do I tell Python to skip searching the hidden/protected files?
I checked out the How to ignore hidden files using os.listdir()? but the solution I found there only works for files starting with “.”, and that’s not what I need.
Cheers!
Edit – so here’s the code:
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 ""
You can use with the
pywin32module, and manually test forFILE_ATTRIBUTE_HIDDENor any number of attributeslike so:
After you alter a file, take a look in the folder, it won’t be hidden anymore.
Found this information here and here: Checking file attributes in python
Alternatively, you can try to use the
os.statfunction, whose docs here and then use thestatmodule to further understand what you’re looking at.Found these relevant questions. (python) meaning of st_mode and How can I get a file's permission mask?