Last active
June 9, 2023 15:11
-
-
Save hdf/7159128 to your computer and use it in GitHub Desktop.
Usage:dirlist.py c:\ > c_list.txt
This file contains 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, sys | |
cdir = '.' | |
if len(sys.argv) > 1: | |
cdir = sys.argv[1] | |
for dirname, dirnames, filenames in os.walk(cdir): | |
dirname = os.path.realpath(dirname) | |
ending = '' | |
try: | |
for subdirname in dirnames: | |
ending = subdirname | |
print('DIR: ' + os.path.join(dirname, subdirname)) | |
for filename in filenames: | |
ending = filename | |
print('FILE: ' + os.path.join(dirname, filename)) | |
except: | |
try: | |
print(bytes('Problematic name: ', encoding='utf-8') + \ | |
dirname.encode('utf-8', 'surrogateescape') + b'\\' + \ | |
ending.encode('utf-8', 'surrogateescape')) | |
except: | |
print(bytes('Extra problematic name: ', encoding='utf-16') + \ | |
dirname.encode('utf-16', 'replace') + b'\\' + \ | |
ending.encode('utf-16', 'replace')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment