使用 Python 代码从局域网共享盘 \192.168.1.2\tools 文件夹复制 '1.k' 和 '2.k' 文件到当前目录 D:\code。

假设当前目录为 D:\code,可以使用以下代码实现:

import shutil

src_dir = r'\\192.168.1.2\tools'
dst_dir = r'D:\code'

shutil.copy2(src_dir + r'\1.k', dst_dir)
shutil.copy2(src_dir + r'\2.k', dst_dir)

其中,shutil 模块提供了复制文件的方法 copy2,src_dir 为共享盘的路径,dst_dir 为当前目录的路径,使用 r 前缀表示原始字符串,避免转义字符的影响。

Python 复制局域网共享盘文件到本地目录

原文地址: http://www.cveoy.top/t/topic/oK15 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录