def backupFile(fn, outputPath = None, overwrite = False): new_fn = FilenameHelper.addDateToFilename(fn) if outputPath: today= datetime.datetime.now().strftime('%Y-%m-%d') npath = os.path.join(outputPath, today ) if not os.path.exists(npath): os.makedirs(npath) filename = os.path.split(fn)[1] new_fn = os.path.join(npath, filename) if os.path.exists(new_fn) and not overwrite: raise IOError("File %s already exists function is set to not overwrite" % new_fn) elif os.path.exists(new_fn) and overwrite: new_fn = FilenameHelper.addDateToFilename(new_fn) shutil.copy2(fn, new_fn) if not os.path.exists(new_fn): raise IOError("Could not copy file %s to %s" %( fn, new_fn)) return new_fn
try: print "\rString decode %10s : %s" %(enc, name_unicode.decode(enc)) except: print "\rCannot decode string for %s " % (enc) print "=" *50 word = 'Piráña' letters = list(word) for let in letters: msg = let + " : " for x in let: msg += str(hex(ord(x))) print msg print '-'*60 fn =r'C:\Temp\python\iptcconvert\output\1996-DesignaciónAdministradorPCC.jpg' exists = os.path.exists(fn) print "%s [%d] %s" % (fn, len(fn), exists) print '-'*60 fn = ur'C:\Temp\python\iptcconvert\output\1996-DesignaciónAdministradorPCC.jpg' exists = os.path.exists(fn) print "%s [%d] %s" % (fn, len(fn), exists) nfn = FilenameHelper.addDateToFilename(fn) copy2(fn, nfn) exists = os.path.exists(nfn) print "%s [%d] %s" % (nfn, len(nfn), exists)