Python: Check If File Exists - so it goes
With a few commands, you can query in Python, if a file exists:
- Add the above to your Code the command "from pathlib import Path" (without the quotation marks).
- You then store the path to your file in a variable: "my_file = Path("/path/to/file")"
- With a command like "if my_file.is_file():" you can query, for example, whether the file exists.
- If a directory exists, you can, for example, with the command "if my_file.is_dir():" queries.
On our topic page for the Python programming language, you will find additional Tutorials for programming. There we will show you the example of how to use Python with MySQL connect and query your data can.