blob: e0220b544329361f100e90a821ee200e13cfa212 [file] [log] [blame]
Benjamin Peterson90f5ba52010-03-11 22:53:45 +00001#! /usr/bin/env python3
Guido van Rossum5378d5c1991-12-18 13:38:27 +00002
3# Copy one file's atime and mtime to another
4
5import sys
Guido van Rossum9a6757d1992-03-30 11:15:26 +00006import os
Guido van Rossum5378d5c1991-12-18 13:38:27 +00007from stat import ST_ATIME, ST_MTIME # Really constants 7 and 8
8
9def main():
Georg Brandl8efadf52008-05-16 15:23:30 +000010 if len(sys.argv) != 3:
Tim Peters70c43782001-01-17 08:48:39 +000011 sys.stderr.write('usage: copytime source destination\n')
12 sys.exit(2)
13 file1, file2 = sys.argv[1], sys.argv[2]
14 try:
15 stat1 = os.stat(file1)
16 except os.error:
17 sys.stderr.write(file1 + ': cannot stat\n')
18 sys.exit(1)
19 try:
20 os.utime(file2, (stat1[ST_ATIME], stat1[ST_MTIME]))
21 except os.error:
22 sys.stderr.write(file2 + ': cannot change time\n')
23 sys.exit(2)
Guido van Rossum5378d5c1991-12-18 13:38:27 +000024
Andrew M. Kuchlinge236b382004-08-09 17:27:55 +000025if __name__ == '__main__':
26 main()