else/Toolbox/touch.py

22 lines
563 B
Python
Raw Normal View History

2016-12-05 01:50:52 +00:00
'''
Create the file, or update the last modified timestamp.
'''
2016-11-18 06:24:52 +00:00
import glob
import os
import sys
2016-12-13 03:53:21 +00:00
def touch(glob_pattern):
2016-11-18 06:24:52 +00:00
filenames = glob.glob(glob_pattern)
if len(filenames) == 0:
2016-12-13 03:53:21 +00:00
print(glob_pattern.encode('ascii', 'replace').decode())
2016-11-18 06:24:52 +00:00
open(glob_pattern, 'a').close()
else:
for filename in filenames:
2016-12-13 03:53:21 +00:00
print(filename.encode('ascii', 'replace').decode())
2016-11-18 06:24:52 +00:00
os.utime(filename)
2016-12-13 03:53:21 +00:00
if __name__ == '__main__':
glob_patterns = sys.argv[1:]
for glob_pattern in glob_patterns:
touch(glob_pattern)