一、测试目录&测试文件
二、代码实现
1、
# -*- coding:UTF-8 -*- import os from time import sleep DOWNLOAD_PATH = 'D:\\download_file' # 检查下载文件 def check_download_file(f): try: if os.path.exists(DOWNLOAD_PATH): sleep(1.2) for file in os.listdir(DOWNLOAD_PATH): if f in file: print("【{0}】文件存在".format(file)) return True else: print("文件不存在") return False except: print("路径不存在") # 删除文件 def delete_download_file(): for file in os.listdir(DOWNLOAD_PATH): if len(file) > 0: os.remove(DOWNLOAD_PATH + "\\" + file) print("删除【{0}】文件成功".format(file)) else: print("删除文件失败") if __name__ == '__main__': # delete_download_file() check_download_file(f='BKY')
2、
# -*- coding:UTF-8 -*- import os DOWNLOAD_PATH = 'D:\\download_file' # 检查操作前后的文件数量 file = int(len([lists for lists in os.listdir(DOWNLOAD_PATH) if os.path.isfile(os.path.join(DOWNLOAD_PATH, lists))])) print("文件数量为【{0}】个".format(file))
标签:print,download,Part,UI,file,自动化,DOWNLOAD,PATH,os From: https://www.cnblogs.com/TSmagic/p/17475181.html