Apr-01-2020, 04:10 PM
Hello Community,
I am using
- macOS 10.15.4
- Python 3.8.2 (via Mac Ports)
In the macOS security settings the terminal has full disk access.
I try to check if a certain path and file exists. When I use () in my if statement using pathlib I got false. When I do not use () in the if statement I got true.
Can someone please explain this difference when using pathlib.
Does someone has similar setup and can say if os.path.exists is working or not.
My code:
Regards
—Christian
I am using
- macOS 10.15.4
- Python 3.8.2 (via Mac Ports)
In the macOS security settings the terminal has full disk access.
I try to check if a certain path and file exists. When I use () in my if statement using pathlib I got false. When I do not use () in the if statement I got true.
Can someone please explain this difference when using pathlib.
Does someone has similar setup and can say if os.path.exists is working or not.
My code:
import os
import platform
from pathlib import Path
path_Safari = "~/Library/Safari/"
path_Safari_Bookmark = "~/Library/Safari/Bookmarks.plist"
def check_os_version():
print("Check OS version")
print("================")
print("")
os_general = platform.system()
print("My OS is:", os_general)
os_release = platform.release()
print("My OS release is:", os_release)
print("")
if os_general == "Darwin":
print("I have to do something")
print("")
if os.path.exists(path_Safari):
print("Path: " + path_Safari + "exist")
print("")
else:
print("Path: " + path_Safari + " does not exist or is not accessible. Please check")
print("")
if os.path.exists(path_Safari_Bookmark):
print("Path: " + path_Safari_Bookmark + "exist")
print("")
else:
print("Path: " + path_Safari_Bookmark + " does not exist or is not accessible. Please check")
print("")
my_dir = Path(path_Safari)
if my_dir.is_dir():
print("pathlib dir: OK")
print("")
else:
print("pathlib dir: NOT OK")
print("")
my_file = Path(path_Safari_Bookmark)
if my_file.is_file:
print("pathlib file: OK")
print("")
else:
print("pathlib dir: NOT OK")
print("")
check_os_version()My result:Quote:Check OS version
================
My OS is: Darwin
My OS release is: 19.4.0
I have to do something
Path: ~/Library/Safari/ does not exist or is not accessible. Please check
Path: ~/Library/Safari/Bookmarks.plist does not exist or is not accessible. Please check
pathlib dir: NOT OK
pathlib file: OK
Regards
—Christian
