Skip to content

Commit

Permalink
Implement FileNotFoundError handling to not crash
Browse files Browse the repository at this point in the history
  • Loading branch information
phoenixrising1800 committed Sep 8, 2023
1 parent 72ca071 commit f933c80
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import sys
from bitstring import ConstBitStream
from src.sms import *
from src.contacts import *
Expand All @@ -8,14 +9,18 @@ def input_file():
return filename

def main():
## Prompt user to specify file from path (DOES NOT HANDLE ERRORS PROPERLY)
## Prompt user to specify file from path
file = input_file()
while file == "":
print("Enter valid path to file")
file = input_file()

## Print file size
file_size_bytes = os.path.getsize(file)
## Print file size (if file exists)
try:
file_size_bytes = os.path.getsize(file)
except FileNotFoundError:
print("File does not exist, try again.")
sys.exit(1)
print(f'File size: {file_size_bytes} bytes')
print("*****************************************************************")

Expand Down

0 comments on commit f933c80

Please sign in to comment.