File Operations in Python: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
(Created page with "=Internal= * Python Code Examples =Check whether a File Exists=")
 
Line 3: Line 3:


=Check whether a File Exists=
=Check whether a File Exists=
<syntaxhighlight lang='python'>
from os.path import exists
file_exists = exists(path_to_file)
</syntaxhighlight>
<syntaxhighlight lang='python'>
from pathlib import Path
path = Path(path_to_file)
path.is_file()
</syntaxhighlight>

Revision as of 23:47, 20 January 2022

Internal

Check whether a File Exists

from os.path import exists
file_exists = exists(path_to_file)
from pathlib import Path
path = Path(path_to_file)
path.is_file()