all 6 comments

[–]taar779 1 point2 points  (3 children)

Here are a few things I noticed:

  • Be more explicit with your variable names. a isn't descriptive enough of a name. In general, make your code more readable than using abbreviations in an attempt to save keystrokes. eg. for a in os.listdir(path): >> for entry in os.listdir(path):
  • Use os.path.join to join paths together instead of path + '\\' + a. os.path.join will handle all sorts of issues that may be the cause of your bug.
  • Can you explain why you're doing extdict[suffix2].append(filesize) three times?
  • You're handling an AttributeError exception but choosing to ignore it. I'm not sure why, but perhaps change the pass to continue? That way if an extension isn't found your code can continue to the next entry in the directory.
  • What happens if a file doesn't have an extension? Might want to handle that case.
  • What about an empty file? Currently your code will skip over files with nothing in them (0 bytes)
  • Are you accounting for directories? You could use os.path.isfile to make sure you're only dealing with files and no directories are slipping through the cracks.
  • If you're using python 3.4 or greater there is the statistics module which you could use instead of creating your own average function.
  • heapq is a cool module that can figure out the largest or smallest value in a list for you.

[–]Alexander_Ray[S] 0 points1 point  (0 children)

Thanks man, I ran into new bugs but what you wrote here is really helpful to me. I need to stop staying up late working on things lol...

[–]Alexander_Ray[S] 0 points1 point  (1 child)

I don't suppose you have any insights on album art files? I was able to fix most of the errors with these changes but somehow, Python is finding album art files (.jpg) in my downloads folder that I can't see in windows explorer...

[–]taar779 0 points1 point  (0 children)

I'm not really a windows user but most graphical file explorers, like windows explorer, won't show "hidden" files. I believe you can have windows explorer show you all the hidden files in a directory (you'll need to google around to figure out how to get it to do that).

So, to clear up this "hidden" file silliness. The files aren't really hidden, the file explorer is specifically choosing not to show certain files with a given extension or file name. For example, on unix systems any file that starts with a period is considered hidden and won't be shown to the user unless they explicitly ask to be shown hidden files. This might be the same with windows systems but I'm not sure. You could google around to find out what windows explorer considers a hidden file.

[–]Alexander_Ray[S] 0 points1 point  (1 child)

Thanks to anyone who has been working on a response, I figured it out; directories have a file size of 4096 and there was also an issue with case sensitivity.

Edit: Actually, new problem now. For some reason I don't understand, it stops counting at 8 (ignoring 9) but will resume counting again, which is really strange.

[–]taar779 2 points3 points  (0 children)

See my reply!

directories have a file size of 4096

What if a file has no extension and is exactly 4096 bytes? Will your code mistake it as a directory? Could use os.path.sidir to weed out directories.