view copyFiles.py @ 0:5e33fa5a2fdc

initial
author Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
date Tue, 19 Aug 2014 14:12:52 +0200
parents
children
line wrap: on
line source

from _csv import Error
start ="/Volumes/Folivora/MPG_Archiv/"
target = "/Volumes/MPGARCHIV/input/"


import os
import shutil

errorf = open("/tmp/error.out","w",encoding="utf-8")
errorf.write("START")

for root, dirs, files in os.walk(start, topdown=False):
    for name in files:
        path = os.path.join(root, name)
        ext = os.path.splitext(path)
        print (name)
        if ext[1] == ".pdf":
            
            fld = os.path.split(root)
            print (fld)
            neu = os.path.join(target,fld[1]+"___"+name.replace(" ","_"))
            if not os.path.exists(neu):
                try:
                    shutil.copy(path, neu)
                except:
                    errorf.write(path+"\n")
                print (path)
            else:
                print("EXISTS:" + path)
                            
errorf.close();   
            
        
        
    #for name in dirs:
    #    print(os.path.join(root, name))