Last active
August 8, 2017 00:27
-
-
Save hamitozdemir/14ed1b7791294cc10b5dd0b55ed3d6a0 to your computer and use it in GitHub Desktop.
Creates a list of files/directories in the current directory into a text file
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
import os | |
import io | |
import sys | |
class Reader(): | |
def __init__(self, file): | |
archive = '' | |
for dirname, dirnames, filenames in os.walk(os.getcwd()): | |
print('.', end='') | |
#print path to all subdirectories first | |
for subdirname in dirnames: | |
archive += os.path.join(dirname, subdirname) + '\n' | |
#print path to all filenames | |
for filename in filenames: | |
archive += os.path.join(dirname, filename) + '\n' | |
try: | |
with io.open(str(file), 'w', encoding='utf8') as f: | |
f.write(archive) | |
except IOError: | |
print('error') | |
if __name__ == '__main__': | |
app = Reader(sys.argv[1]) | |
''' | |
Usage in command line: | |
>Python Reader.py manifest.txt | |
Creates a list of files in the current dir and subdirs to 'manifest.txt' | |
which will be placed to the current directory | |
Needs the absolute location of Reader.py if it's in a different location | |
You can remove sys.argv[1] and get rid of file variable for a static filename | |
''' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment