因此,正如标题所示,我是Python新手,我的第一个项目是一个脚本,它将检查5个目录中是否存在特定的文件。如果存在,我希望它给我发电子邮件,它在每个路径中找到的文件名。你知道吗
这是我目前掌握的情况。。你知道吗
from pathlib import *
adr01_file = Path("/home/skeer/Documents/Projects/Python_temp/home/adr01/upload/monitor*.pgp")
if adr01_file.is_file():
print("File exists")
else:
print("File does not exist")
chpt_file = Path("/home/skeer/Documents/Projects/Python_temp/home/chpt/upload/monitor*.pgp")
if adr01_file.is_file():
print("File exists")
else:
print("File does not exist")
emb01_file = Path("/home/skeer/Documents/Projects/Python_temp/home/emb01/upload/monitor*.pgp")
if adr01_file.is_file():
print("File exists")
else:
print("File does not exist")
exp01_file = Path("/home/skeer/Documents/Projects/Python_temp/home/exp01/upload/monitor*.pgp")
if adr01_file.is_file():
print("File exists")
else:
print("File does not exist")
iix01_file = Path("/home/skeer/Documents/Projects/Python_temp/home/iix01/upload/monitor*.pgp")
if adr01_file.is_file():
print('File exists')
else:
print('File does not exist')
但我得到的是每一行的“文件存在”。即使在任何目录中除了adr01之外没有任何文件。你知道吗
感谢所有提示/提示。你知道吗
这是因为您检查了五次
adr01_file
的存在性—您忘记了更改if
语句中的变量。另外,我在你的路径中看到了*
,你的意思是字面意思还是通配符?如果再晚一点,就不行了。你知道吗相关问题 更多 >
编程相关推荐