Skip to content

Test File Path in Python on Windows

Vic Phan edited this page Feb 28, 2023 · 1 revision

• Press the Windows key type “python” and select the “IDLE” application.
image

• Type import os and press the “Enter” key to import the os module.
image

• Type from pathlib import PureWindowsPath and press the Enter key to import the PureWindowsPath object from the pathlib module.
image

• 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.
image

• Type os.path.exists(< variable >) and press the Enter key to test the file path and it will return either True or False.
image

• Type exit() or quit() and press the “Enter” key to exit the IDLE interactive shell. / • image

• Select “OK.”
image

Viccy GitHub

Clone this wiki locally