简体   繁体   English

python中如何将目录中的文件移动到另一个目录

[英]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.

相关问题 如何将文件从一个目录移动到另一个目录? - How to move a file from one directory to another? Python:如何根据单独列表中的项目将文件从目录移动到另一个目录? - Python: How to move file from directory to another based on items in the separate list? 如何移动Python中的一个目录? - How to move a directory in Python? 如何使用 python 将 email 从一个目录移动到另一个目录 - How can I move an email from a directory to another using python 为什么 python 程序在我将文件移动到另一个目录后继续写入它原来所在的目录? - Why does a python program continue to write to the directory in which it was originally located, after I move the file to another directory? 如何移动与同一目录中的另一个文件以相同 X 字符开头的文件,并移动最轻的一个 - How to move a file that starts with the same X characters as another file in the same Directory, and move the lightest one 如何从另一个目录导入python文件 - how to import python file from another directory 我如何告诉 python 移动到目录中的下一个文件? - How do I tell python to move to the next file in the directory? Python FTP ftplib 将整个文件夹移动到另一个目录失败,并显示“无法链接到另一个设备上的文件” - Python FTP ftplib move an entire folder to another directory fails with "Cannot link to a file on another device" 完成传输后将文件移动到另一个目录 - Move file to another directory once it is done transferring
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM