溫馨提示×

python isfile能檢查文件權限嗎

小樊
85
2024-12-04 14:16:02
欄目: 編程語言

os.path.isfile() 函數用于檢查給定的路徑是否是一個存在的文件

import os

file_path = "path/to/your/file"

if os.path.isfile(file_path):
    print("The given path is a file.")
else:
    print("The given path is not a file or does not exist.")

如果你想要檢查文件的權限,可以使用 os.access() 函數。例如,要檢查文件是否可讀,可以這樣做:

import os

file_path = "path/to/your/file"

if os.access(file_path, os.R_OK):
    print("The file is readable.")
else:
    print("The file is not readable or does not exist.")

0
亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女