My file sorting project
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.
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.
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()