Python batch copy files

巴扎黑
Release: 2016-12-08 09:34:30
Original
1267 people have browsed it

An excel is exported from the database, which contains the file names of some image files. The corresponding files need to be downloaded from the server. The program does not provide a batch export function for images. It is just temporary data statistics. You need to manually export the corresponding files in excel. .

1. Copy the file name column in excel, paste it into a blank text file, name it filelist.txt, and upload it to the server.

2. Use script export on the server, python script:

#! 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()
Copy after login


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template