def touch(path, times=None, dirs=False):
''' perform UNIX touch with extra
based on: http://stackoverflow.com/questions/12654772/create-empty-file-using-python
Args:
path: file path to touch
times: a 2-tuple of the form (atime, mtime) where each member is an int or float expressing seconds.
defaults to current time.
dirs: is set, create folders if not exists
'''
if dirs:
basedir = os.path.dirname(path)
if not os.path.exists(basedir):
os.makedirs(basedir)
with open(path, 'a'):
os.utime(path, times=times)
评论列表
文章目录