Added invalid directory exceptions to fileList.py
This commit is contained in:
parent
c0459353c2
commit
6cd9101be0
|
@ -8,9 +8,18 @@ def main():
|
||||||
|
|
||||||
|
|
||||||
def printFilesSize(path):
|
def printFilesSize(path):
|
||||||
|
try:
|
||||||
|
directory = os.listdir(path)
|
||||||
|
except FileNotFoundError:
|
||||||
|
print(f"[Error] Unable to find that directory: '{os.path.abspath(path)}'")
|
||||||
|
exit(1)
|
||||||
|
except NotADirectoryError:
|
||||||
|
print(f"[Error] Path is not a directory: '{os.path.abspath(path)}'")
|
||||||
|
exit(1)
|
||||||
|
else:
|
||||||
print(f'|{"-"*78}|')
|
print(f'|{"-"*78}|')
|
||||||
print(f'| {"File":<63} {"Size":>12} |\n|{"-"*78}|')
|
print(f'| {"File":<63} {"Size":>12} |\n|{"-"*78}|')
|
||||||
for file in os.listdir(path):
|
for file in directory:
|
||||||
base_size = os.stat(f'{path}/{file}').st_size
|
base_size = os.stat(f'{path}/{file}').st_size
|
||||||
if os.path.isdir(f'{path}/{file}'):
|
if os.path.isdir(f'{path}/{file}'):
|
||||||
size = "-Directory-"
|
size = "-Directory-"
|
||||||
|
|
Loading…
Reference in New Issue