So, I decided while I was in missouri to start a project... Didnt quite realize what I was getting myself into.
I wanted to create a python script to read all the files in a folder, then sort the MP3 files into folders by artist and album. I spent about a week on it, in whatever sparetime I had, lots of googling modules and various syntax, and came out with this. I already know it is not the most efficient of code, so any pointers on what I should clean up would be great.
All this does so far is crawl through all directories and subdirectories and index the filepaths into a list.
Code:import os import sys dirname = (os.getcwd()) print(dirname) q=[] d=[] def subdir(dirList): for v in dirList: d.extend([os.path.join(v, f) for f in os.listdir(v) if os.path.isfile(os.path.join(v, f))]) b = [os.path.join(v, f) for f in os.listdir(v) if os.path.isdir(os.path.join(v, f))] if b: q.append(b) if q: subdir(q.pop(0)) def crawl(directory): files = os.listdir(directory) d.extend([os.path.join(directory, f) for f in os.listdir(directory) if os.path.isfile(os.path.join(directory, f))]) b = [os.path.join(directory, f) for f in os.listdir(directory) if os.path.isdir(os.path.join(directory, f))] print(['Here be D']+d) if b: subdir(b) else: return print('Done') crawl(dirname) print(d) f=open('filed.txt','w') f.write(str(d)) f.close()
Results 1 to 1 of 1
Thread: My file sorting project
- 24 Dec. 2010 07:38am #1
My file sorting project
LG's resident grammar nazi.
Need warez? I can probably find it for you. Throw me a PM.
For all of my sales, if you refer a buyer to me and they make a purchase, you can recieve 5%