Last active
July 18, 2018 03:47
-
-
Save BlogBlocks/4f3242cb979cd537907a21ae67f89105 to your computer and use it in GitHub Desktop.
ists all file in a directory and copies the list to a file this will provide the full path to the MP3/ directory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| USAGE: | |
| import dir2file | |
| PATH = "MP3/" | |
| mfile = "GISTstore/muz.list" | |
| dir2file.mkFile(mfile, PATH) | |
| lists all file in a directory and copies the list to a file | |
| this will provide the full path to the MP3/ directory | |
| import dir2file | |
| PATH = "MP3/" | |
| fullpath = dir2file.listpath(PATH) | |
| print fillpath | |
| """ | |
| import os.path | |
| from os import listdir, getcwd | |
| def mp3list(PATH): | |
| abs_path = os.path.join(os.getcwd(),PATH) | |
| dir_files = os.listdir(abs_path) | |
| return dir_files | |
| def mkFile(mfile, PATH): | |
| mFiles = open(mfile, "w");mFiles.close() | |
| lst = mp3list(PATH) | |
| lst = str(lst) | |
| lst = lst.replace(",","\n");lst = lst.replace("'","") | |
| lst = lst.replace("[","");lst = lst.replace("]","") | |
| lst = lst.replace(" ","") | |
| print lst | |
| mFiles = open(mfile, "a") | |
| mFiles.write(lst) | |
| mFiles.close() | |
| return mfile | |
| def listpath(PATH): | |
| abs_path = os.path.join(os.getcwd(),PATH) | |
| abpath = (abs_path) | |
| return abpath |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment