查看: 1597|回复: 0

复制/移动文件

[复制链接]

665

主题

1234

帖子

6575

积分

xdtech

Rank: 5Rank: 5

积分
6575
发表于 2019-4-20 15:47:28 | 显示全部楼层 |阅读模式
本帖最后由 shaoheshaohe 于 2019-4-20 15:48 编辑

# -*- coding: utf-8 -*-
#!/usr/bin/python
#test_copyfile.py
import os,shutil
def mymovefile(srcfile,dstfile):   
if not os.path.isfile(srcfile):      
print "%s not exist!"%(srcfile)   
else:        
fpath,fname=os.path.split(dstfile)   
#分离文件名和路径      

if not os.path.exists(fpath):            
os.makedirs(fpath)               
#创建路径        
shutil.move(srcfile,dstfile)         
#移动文件        
print "move %s -> %s"%( srcfile,dstfile)def mycopyfile(srcfile,dstfile):   

if not os.path.isfile(srcfile):        
print "%s not exist!"%(srcfile)   
else:        fpath,fname=os.path.split(dstfile)    #分离文件名和路径      

if not os.path.exists(fpath):           
os.makedirs(fpath)               
#创建路径        
shutil.copyfile(srcfile,dstfile)      
#复制文件        
print "copy %s -> %s"%( srcfile,dstfile)

srcfile=
'/Users/xxx/git/project1/test.sh'

dstfile=
'/Users/xxx/tmp/tmp/1/test.sh'

mymovefile(srcfile,dstfile)

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表