Python例子
- Python复制文件到另外一个文件夹
- requests POST请求发送文件和数据
- Python设置函数最大执行时间
- Python例子-图片转成base64格式
- Python获取用户IP地址
- requests.get(url,headers = headers).text解码为中文
- Python例子-Python结合正则去除所有html标签
- Python例子-图片验证码
- Python例子-将一个list的值加入字典,然后再插入到一个空列表
- Python例子-爬取糗事百科首页内容
- Python例子-urllib模拟游览器
- Python例子-读取远程页面并写入本地页面
- Python例子-通过装饰器实现已有函数执行时间的统计
- Python例子-使用闭包函数输出不同人的对话
- Python例子-面向对象(烤地瓜)
- Python例子-复制文件
- Python例子-计算阶乘 n! = 1 * 2 * 3 * ... * n
- Python例子-8个老师分配到3个办公室
- Python例子-求1~100中平方根是整数的数
- Python例子-求100-999之间所有的"水仙花数"
- Python例子-1、2、3、4组成互不相同不重复的三位数
- Python例子-年份是否是闰年
- Python例子-设计“过7游戏”
- Python例子-九九乘法表
- Python例子-统计字符串中,各个字符的个数
- Python例子-测试身材是否标准
- Python例子-计算1~100的累加和
- Python例子-猜拳游戏
- Python例子上公交车有座位可以坐下
Python复制文件到另外一个文件夹
在实际工作中,我们会用到python复制文件到另外一个文件夹。上代码:
import os import shutil def copyfile(file_path, back_dir): # 复制函数 if not os.path.isfile(file_path): print("%s not exist!" % (file_path)) else: fpath, fname = os.path.split(file_path) # 分离文件名和路径 if not os.path.exists(back_dir): os.makedirs(back_dir) # 创建路径 shutil.copy(file_path, back_dir + fname) # 复制文件 print("copy %s -> %s" % (file_path, back_dir + fname)) # if __name__ == '__main__': # file_path = r'/www/wwwroot/xray_scan/scan_result/https_66_220_31_47.html' # back_dir = r'/www/wwwroot/xray_scan/scan_result_back/' # copyfile(file_path, back_dir)
最后修改:2021-07-31 17:45:00