
python 怎么实现两台服务器上批量复制文件
2个回答
2016-04-25
展开全部
1、把excel里文件名那一列复制,粘进一个空白的文本文件,命名为filelist.txt,上传到服务器。
2、在服务器上使用脚本导出,python脚本 fileCp.py 。
代码示例:
#! python
#coding:utf-8
##!/usr/bin/python
# Filename : fileCp.py
import sys
import os
import shutil
fileList='filelist.txt'
targetDir='files'
filedir = open(fileList)
line = filedir.readline()
log = open('running.log','w')
while line:
line = line.strip('\n');
basename = os.path.basename(line)
exists = os.path.exists(line)
if exists :
print 'copy '+line+' to '+os.getcwd()+'/'+targetDir+'/'+basename
log.write('copy '+line+' to '+os.getcwd()+'/'+targetDir+'/'+basename+'\r\n')
shutil.copy(line,targetDir+'/'+basename)
else:
print line+' not exists'
log.write(line+' not exists'+'\r\n')
line = filedir.readline()
log.close()
2、在服务器上使用脚本导出,python脚本 fileCp.py 。
代码示例:
#! python
#coding:utf-8
##!/usr/bin/python
# Filename : fileCp.py
import sys
import os
import shutil
fileList='filelist.txt'
targetDir='files'
filedir = open(fileList)
line = filedir.readline()
log = open('running.log','w')
while line:
line = line.strip('\n');
basename = os.path.basename(line)
exists = os.path.exists(line)
if exists :
print 'copy '+line+' to '+os.getcwd()+'/'+targetDir+'/'+basename
log.write('copy '+line+' to '+os.getcwd()+'/'+targetDir+'/'+basename+'\r\n')
shutil.copy(line,targetDir+'/'+basename)
else:
print line+' not exists'
log.write(line+' not exists'+'\r\n')
line = filedir.readline()
log.close()
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |