Note that there are some explanatory texts on larger screens.

plurals
  1. POpython os.listdir() shows protected files
    primarykey
    data
    text
    <p>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 <code>if file[-4:] in (".jpg",".bmp",".png")</code>, if true, it found a picture file. Just to make it clear, the structure of my folders is:</p> <ul> <li>Music folder <ul> <li>Arctic Monkeys <ul> <li>Humbug (2009)</li> <li>Suck it and see (2011)</li> </ul></li> <li>Morphine <ul> <li>Cure For Pain (1993)</li> </ul></li> </ul></li> </ul> <p>.. 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 <a href="https://dl.dropbox.com/u/34696560/python/ss.jpg" rel="nofollow noreferrer">which doesn't show up in the command prompt</a> so I tried "Show hidden files/folders" and still nothing. However, <a href="https://dl.dropbox.com/u/34696560/python/hidden.jpg" rel="nofollow noreferrer">the files show up once I uncheck "Hide protected operating system files"</a>, so that's kinda weird.</p> <p>My question is - <strong>how do I tell Python to skip searching the hidden/protected files?</strong> I checked out the <a href="https://stackoverflow.com/questions/7099290/how-to-ignore-hidden-files-using-os-listdir-python">How to ignore hidden files using os.listdir()?</a> but the solution I found there only works for files starting with ".", and that's not what I need.</p> <p>Cheers!</p> <hr> <p>Edit - so here's the code:</p> <pre><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 "" </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload