def touch(path): import os, time now = time.time() try: # assume it's there os.utime(path, (now, now)) except os.error: # if it isn't, try creating the directory, # a file with that name os.makedirs(os.path.dirname(path)) open(path, "w").close() os.utime(path, (now, now))