mercredi 29 octobre 2014

Shutil.copy too slow


Vote count:

0




I have thousands of excel file for several years. All the files have year (e.g. 2010, 2011 etc) embedded in their name. Some of the excel file contains keywords like (Closure, closure) in the sheet. These keywords may be present within a sentence (e.g. Road closure due to construction). I wanted to write a code so that I can copy the files for a specific year which does not have those keywords in its sheet. The following code is working, but it is too slow. Any ideas how to make it faster?



import glob
import os
import shutil
import xlrd
os.chdir("G:/_Traffic Counts/Traffic Volumes/")
choice = raw_input("Specify the Year to Copy (e.g. 2012) and Press Enter ")
location = ("C:/Users/tsengineer/Desktop/Trial_JM/")
notcopy = ("closure", "Closure")
i = 0
for file in glob.glob("*.xls"):
if choice in file:
book = xlrd.open_workbook(file)
sheet = book.sheet_by_index(0)
for row in range(sheet.nrows):
for column in range(sheet.ncols):
if any(s in str(sheet.cell(row,column).value) for s in notcopy):
pass
else:
shutil.copy(file, location)
print "Copying...", i+1
i = i + 1
print "Copying Complete. Total File Copied:", i


asked 43 secs ago

Joy

21






Shutil.copy too slow

Aucun commentaire:

Enregistrer un commentaire