Test File Path in Python on Windows - DevPops-Inc/python GitHub Wiki
• Press the Windows key type “python” and select the “IDLE” application.
•
• Type import os
and press the “Enter” key to import the os
module.
•
• Type from pathlib import PureWindowsPath
and press the Enter key to import the PureWindowsPath
object from the pathlib
module.
•
• Type variable = PureWindowsPath(“< file path >”)
and press the Enter key to declare a variable and set its value as the file path you wish to test.
•
• Type os.path.exists(< variable >)
and press the Enter key to test the file path and it will return either True
or False
.
•
• Type exit()
or quit()
and press the “Enter” key to exit the IDLE interactive shell. /
•
• Select “OK.”
•