• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell
您的位置:首页 > 脚本语言 >python > python复制文件的方法实例详解

python复制文件的方法实例详解

作者: 字体:[增加 减小] 来源:互联网

通过本文主要向大家介绍了python开发技术详解,python os模块详解,python正则表达式详解,python 字典详解,python类详解等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

本文实例讲述了python复制文件的方法。分享给大家供大家参考。具体分析如下:

这里涉及Python复制文件在实际操作方案中的实际应用以及Python复制文件 的相关代码说明,希望你会有所收获。

Python复制文件:

import shutil 
import os 
import os.path 
src = " d:\\download\\test\\myfile1.txt " 
dst = " d:\\download\\test\\myfile2.txt " 
dst2 = " d:/download/test/

</div>

测试文件夹.txt "

dir1 = os.path.dirname(src) 
print ( " dir1 %s " % dir1) 
if (os.path.exists(src) == False): 
os.makedirs(dir1) 
f1 = open(src, " w " ) 
f1.write( " line a\n " ) 
f1.write( " line b\n " ) 
f1.close() 
shutil.copyfile(src, dst) 
shutil.copyfile(src, dst2) 
f2 = open(dst, " r " ) 
for line in f2: 
print (line) 
f2.close() 

</div>

测试复制文件夹树

try : 
srcDir = " d:/download/test " 
dstDir = " d:/download/test2 "

</div>

如果dstDir已经存在,那么shutil.copytree方法会报错!这也意味着你不能直接用d:作为目标路径.

shutil.copytree(srcDir, dstDir) 
except Exception as err: 
print (err)
</div>

希望本文所述对大家的Python程序设计有所帮助。

</div>

您可能想查找下面的文章:

  • python中OrderedDict的使用方法详解
  • Python中异常重试的解决方案详解
  • 详解python 字符串和日期之间转换 StringAndDate
  • Python 操作MySQL详解及实例
  • python中OrderedDict的使用方法详解
  • Python中异常重试的解决方案详解
  • 详解python 字符串和日期之间转换 StringAndDate
  • Python 操作MySQL详解及实例
  • Python 登录网站详解及实例
  • 详解Python中类的定义与使用

相关文章

  • 使用Python对MySQL数据操作
  • 跟老齐学Python之数据类型总结
  • 在GitHub Pages上使用Pelican搭建博客的教程
  • 举例讲解Python中的迭代器、生成器与列表解析用法
  • python 解析XML python模块xml.dom解析xml实例代码
  • Python实现快速多线程ping的方法
  • Python实现压缩与解压gzip大文件的方法
  • Python之eval()函数危险性浅析
  • Python中处理字符串之endswith()方法的使用简介
  • python实现dnspod自动更新dns解析的方法

文章分类

  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell

最近更新的内容

    • 高性能web服务器框架Tornado简单实现restful接口及开发实例
    • 以一个投票程序的实例来讲解Python的Django框架使用
    • Python中使用gzip模块压缩文件的简单教程
    • Python科学计算环境推荐——Anaconda
    • 详解Python中类的定义与使用
    • python实现简单购物商城
    • 在Django的视图中使用数据库查询的方法
    • 利用Python开发微信支付的注意事项
    • python3.5实现socket通讯示例(TCP)
    • Linux下通过python访问MySQL、Oracle、SQL Server数据库的方法

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有