复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import os
filename = '15464657761111111.pdf'
pathDir = 'F:/tqcs/sr'
# 判断文件是否存在
if os.path.exists(pathDir + '/' + filename):
print(filename + '文件在' + pathDir + '中存在 ! ')
else:
# 打开文件,不存在则创建
file = open('F:/tqcs/msmj.txt', 'wr')
print(filename + '文件不存在sr目录下,将名字写入到msmj.txt文件中 ! ')
# 将文件名写入到指定文件中
file.write(filename)
# 关闭
file.close()
转载于:https://www.cnblogs.com/bilaisheng/p/10211037.html
最后
以上就是开朗面包最近收集整理的关于Python 判断文件是否存在,不存在则将名称写入指定文件的全部内容,更多相关Python内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复