Skip to content

Instantly share code, notes, and snippets.

@pr0way
Created September 13, 2020 11:54
Show Gist options
  • Save pr0way/2cc733b4088574c769c3352cedb7e9d8 to your computer and use it in GitHub Desktop.
Save pr0way/2cc733b4088574c769c3352cedb7e9d8 to your computer and use it in GitHub Desktop.
Simple script that make a file with list of files in directory and save them into file.
from os import path, scandir
print("Pass path to the directory: ")
mypath = path.join(input())
filename = path.basename(mypath).lower() + '-tracklist.txt'
with scandir(mypath) as it:
list_of_files = [entry.name for entry in it if entry.is_file()]
list_of_files = sorted(list_of_files)
with open(filename, "w") as f:
f.writelines(line + '\n' for line in list_of_files)
## Example:
# Pass path to the directory:
# /home/johndoe/Music/CD1
# We'll getting a sorted list with all our tracks in that directory in file named cd1-tracklist.txt.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment