Created
December 2, 2010 16:34
-
-
Save bilke/725621 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os, glob, errno, sys, time | |
if os.name == 'nt': | |
# Eingabepfad | |
path = '.\\' | |
# Ausgabepfad | |
outPath = path + 'out\\' | |
else: | |
path = './' | |
outPath = path + 'out/' | |
# Erstelle Ausgabepfad | |
try: | |
os.makedirs(outPath) | |
except OSError, exc: | |
if exc.errno == errno.EEXIST: | |
pass | |
else: | |
print 'Could not create output directory' | |
raise | |
# Durchlaufe alle csv-Dateien | |
for infile in glob.glob( os.path.join(path, '*.csv') ): | |
print "Bearbeite " + infile | |
filename = os.path.splitext(infile) | |
# Überprüfen ob Größe ungleich 0 ist, wenn ja, bis 3s warten | |
timeout = 0.0 | |
while os.path.getsize(infile) == 0 and timeout < 3.0: | |
time.sleep(0.1) | |
timeout += 0.1 | |
if timeout >= 3.0: | |
print "Ueberspringe Datei: Dateigroeße gleich 0" | |
continue | |
# Überprüfe, ob sich Größe noch ändert | |
filesize1 = os.path.getsize(infile) | |
time.sleep(0.1) | |
timeout = 0.0 | |
while os.path.getsize(infile) != filesize1 and timeout < 3.0: | |
time.sleep(0.1) | |
timeout += 0.1 | |
if timeout >= 3.0: | |
print "Ueberspringe Datei: Datei wird noch geschrieben" | |
continue | |
f = open(infile, 'r') | |
fout = open(outPath + infile, 'w') | |
i = 0 | |
newFileString = '' | |
# Kopiere Inhalt von csv außer erste Zeile | |
for line in f: | |
if i > 0: | |
newFileString += line | |
i += 1 | |
# Schreibe in csv Ausgabedatei | |
fout.write(newFileString) | |
f.close() | |
fout.close | |
# Lösche csv Eingabedatei | |
os.remove(infile) | |
# Schaue nach Bilddatei | |
inputFilePath = path + filename[0] | |
outputFilePath = outPath + filename[0] | |
if os.path.isfile(inputFilePath + '.tif'): | |
extension = '.tif' | |
elif os.path.isfile(inputFilePath + '.tiff'): | |
extension = '.tiff' | |
elif os.path.isfile(inputFilePath + '.pdf'): | |
extension = '.pdf' | |
# Verschiebe die Bilddatei ins Ausgabeverzeichnis | |
if os.name == 'nt': | |
os.system ("move %s %s" % (inputFilePath + extension, outputFilePath + extension)) | |
else: | |
os.system ("mv %s %s" % (inputFilePath + extension, outputFilePath + extension)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment