python下载文件到本地文件夹

先删除文件夹中所有文件


file1 = os.getcwd().replace('\\', '/') # 获取当前工作目录
print(file1)
file2 = file1[0:file1.find('/Desktop')]
file_dir = os.path.join(file2, 'Downloads/').replace('\\', '/')
print(file_dir)
ls = os.listdir(file_dir)#获取文件路径下的文件名
for i in ls:
c_path = os.path.join(file_dir, i)
print(c_path)
os.remove(c_path)

posted @ 2021-12-14 15:30  我的牛肉面啊  阅读(1415)  评论(0编辑  收藏  举报