扫描二维码下载沐宇APP

沐宇

微信扫码使用沐宇小程序

沐宇

python怎么移动文件到指定文件夹

扬州沐宇科技
2023-09-26 19:04:21
python

要将文件移动到指定文件夹,可以使用shutil模块中的move函数。以下是一个示例代码:

import shutil
# 源文件的路径
source_file = 'path/to/source/file.txt'
# 目标文件夹的路径
target_folder = 'path/to/target/folder'
# 使用shutil.move函数移动文件
shutil.move(source_file, target_folder)

你需要将source_file替换为源文件的路径,将target_folder替换为目标文件夹的路径。执行上述代码后,源文件将被移动到目标文件夹中。

扫码添加客服微信