gpt4 book ai didi

python - 使用 Python 检查 .dat 文件是否存在文件

转载 作者:太空宇宙 更新时间:2023-11-04 10:19:18 25 4
gpt4 key购买 nike

如何检查文件是否存在,使用Python,Python有几种方法可用于检查文件是否存在,在某个目录中

我的代码:

PATH = /abc/python
fname = PATH/UP*.dat

if os.path.isfile(fname)

最佳答案

os.path.exists(file)   # you cant use wildcard here
os.path.isfile(file) # to check for is it a file or not

如果你只想要文件,你可以试试这个:

import os
import glob

PATH = "/abc/python/UP*.dat"
filter(os.path.isfile, glob.glob(PATH))

关于python - 使用 Python 检查 .dat 文件是否存在文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33299633/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com