Skip to content

Instantly share code, notes, and snippets.

@naitsric
Created June 17, 2014 18:23
Show Gist options
  • Save naitsric/70f255e9c7869dc76efc to your computer and use it in GitHub Desktop.
Save naitsric/70f255e9c7869dc76efc to your computer and use it in GitHub Desktop.
Verify Files or Folders With Python
#import xlrd, xlwt
import datetime, time
from time import gmtime, strftime
import os, sys
from shutil import copyfile
#from xlutils.copy import copy
target = ""
result = ""
# av = sys.argv
# if len(av) > 1:
# own = av[1].upper()
class Checker:
def __init__(self, path_target,path_result):
self.extensions = (".docx",".doc")
self.path_target = path_target
self.path_result = path_result
self.log = open(path_result + '\log.txt', 'w')
self.run()
self.log.close()
def run(self):
dirs = os.listdir( self.path_target )
for file in dirs:
if os.path.isfile(self.path_target+"\\"+file):
filename, fileextension = os.path.splitext(file)
try:
if (self.extensions.index(fileextension))>=0:
self.alistDocummet(filename,fileextension)
except Exception, e:
pass
def alistDocummet(self,filename,fileextension):
#self.path_result
real_path_result = self.path_result + "\\"+ strftime("%Y%m%d", gmtime(os.path.getmtime(self.path_target + "\\" + filename + fileextension))) + " " + filename
if not os.path.isdir(real_path_result):
os.mkdir(real_path_result)
self.copyDocumment(filename,fileextension,real_path_result)
def copyDocumment(self,filename,fileextension,real_path_result):
if not os.path.isfile(real_path_result + fileextension):
try:
copyfile(self.path_target + "\\" + filename + fileextension, real_path_result + "\\" + filename + fileextension)
self.log.write(filename + fileextension+ "\n")
except Exception, e:
print e
print "Arranca la verificacion de los Soportes"
Checker(target,result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment