Skip to content

Instantly share code, notes, and snippets.

@BlogBlocks
Last active July 18, 2018 03:47
Show Gist options
  • Select an option

  • Save BlogBlocks/4f3242cb979cd537907a21ae67f89105 to your computer and use it in GitHub Desktop.

Select an option

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
"""
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