[英]How to move a file in a directory to another in python
I have a File that needs to be moved by my python script with shutil but I don't know where the origin location is, how do I find the origin location?我有一个文件需要通过我的 python 脚本使用 shutil 移动,但我不知道原始位置在哪里,如何找到原始位置?
import shutil
import os
name = os.getlogin()
shutil.move(./file.foo, 'C:/Users/'+name+'/AppData/Roaming/Microsoft/Windows/Start Menu/Programs/Startup')
the "file.foo" is in the same directory as my python script “file.foo”与我的 python 脚本位于同一目录中
I have searched everywhere but I cant get a good result even with os.path
and others.我到处搜索,但即使使用
os.path
和其他人也无法获得好的结果。
use shutil.move
method to move a file shutil.move(src, dst, copy_function=copy2)
使用
shutil.move
方法移动文件shutil.move(src, dst, copy_function=copy2)
Recursively move a file or directory (src) to another location (dst) and return the destination.
递归地将文件或目录 (src) 移动到另一个位置 (dst) 并返回目的地。 refer
参考
source = 'path/to/file'
destination = 'path/to/file'
dest = shutil.move(source, destination, copy_function = shutil.copytree)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.