0
tell me how to make a condition: if the file does not exist
tell me how to make a condition: if the file does not exist
4 odpowiedzi
+ 4
Alisa Zaiceva ,
put the part of the code that is trying to open a file in a try... except... construct.
[Edited]:
using to check if a file exists by using os.path or pathlib module does physically check if the file exists. that is ok - no doubts.
but there may be a whole bunch of issues that can happen when accessing or during using the file and make the app crashing: (* = handled by doing the mentioned check)
- file not found *
- no such directory *
- file in use or blocked
- no permission to access
- bad file descriptor: using wrong mode
- no space left on the device
- file is read-only
- resource temporarily unavailable
- network dropped connection
- connection timed out
- connection refused
- input/output error
- .....
+ 2
Google something like "Python file exists" for examples and tutorials
https://www.pythontutorial.net/python-basics/python-check-if-file-exists/
0
Alisa Zaiceva How about doing this in cmd? :-
if exist ... ?