如何使用Python将文件从C驱动器移动到网络驱动器?

时间:2018-10-10 15:11:22

标签: python shutil

这是我提出的上一个问题的后续措施。

我一直在使用python和selenium自动化Web进程,最终结果是几个下载的文件。它们会自动下载到我的C:驱动器的downloads文件夹中。

我想将文件从C:驱动器移到Z:驱动器。但是,Z驱动器是网络驱动器。据我了解,Python无法固有地将文件移动到网络驱动器。

当我运行此脚本时:

source_dir = "C:\\Users\\e1206433\\Downloads\\EstadisticaEjecGlo*.csv\\"
dest_temp = "Z:\\AN\\Produban\\Operations\\"


for file in glob.glob(source_dir):
    shutil.move(source_dir, dest_temp)

print (source_dir) 
#Printing source_dir to ensure the script is reaching the shutil command

终端返回以下内容:

C:\Users\e1206433\Downloads\EstadisticaEjecGlo*.csv\

Process finished with exit code 0

这表明命令正在成功移动文件。 但是,当我检查源目录时,文件仍然存在并且没有移动到网络驱动器中的文件中。

任何人都可以解释如何解决此问题吗?

非常感谢。

1 个答案:

答案 0 :(得分:1)

在使用shutil.move的方法source_dir中,尝试更改为file。 并在\\

之后删除*.csv
source_dir = "C:\\Users\\e1206433\\Downloads\\EstadisticaEjecGlo*.csv"
dest_temp = "Z:\\AN\\Produban\\Operations\\"


for file in glob.glob(source_dir):
    shutil.move(file, dest_temp)

print (source_dir) 
#Printing source_dir to ensure the script is reaching the shutil command
相关问题