import os
import shutil
import time
rootpath = 'D:\\BaiduNetdiskDownload\\2022年\\第1季度'
newPath = 'C:\\Users\Administrator\\Desktop\\测试移动文件'
qfile_Name = '7052'
def find_movefile(rootpath, newPath, qfile_Name):
'''
文件夹目录下遍历查找以 qfile_Name开头的文件,查询到以后,将文件移动到newPath文件夹目录下
:param rootpath:
:param newPath:
:qfile_Name
'''
arrfile = os.listdir(rootpath)
# 判断文件夹中是否以xx开头的文件
results_table = None
for i in range(5):
for filename in arrfile:
if filename.startswith(qfile_Name):
results_table = filename
break
else:
print('查询中')
results_table = None
if results_table != None:
print('开始将下载文件夹里面的内容,移动')
print(results_table)
oldPath = os.path.join(rootpath, results_table)
print(oldPath)
shutil.move(oldPath, newPath)
break
else:
time.sleep(2)
find_movefile(rootpath, newPath, qfile_Name)
上一篇

模拟变轨滑块模拟人工拖动
2020-02-18
下一篇

注册表实现浏览器代理设置
2020-02-18