1 | n/a | #! /usr/bin/env python3 |
---|
2 | n/a | |
---|
3 | n/a | # Copy one file's atime and mtime to another |
---|
4 | n/a | |
---|
5 | n/a | import sys |
---|
6 | n/a | import os |
---|
7 | n/a | from stat import ST_ATIME, ST_MTIME # Really constants 7 and 8 |
---|
8 | n/a | |
---|
9 | n/a | def main(): |
---|
10 | n/a | if len(sys.argv) != 3: |
---|
11 | n/a | sys.stderr.write('usage: copytime source destination\n') |
---|
12 | n/a | sys.exit(2) |
---|
13 | n/a | file1, file2 = sys.argv[1], sys.argv[2] |
---|
14 | n/a | try: |
---|
15 | n/a | stat1 = os.stat(file1) |
---|
16 | n/a | except OSError: |
---|
17 | n/a | sys.stderr.write(file1 + ': cannot stat\n') |
---|
18 | n/a | sys.exit(1) |
---|
19 | n/a | try: |
---|
20 | n/a | os.utime(file2, (stat1[ST_ATIME], stat1[ST_MTIME])) |
---|
21 | n/a | except OSError: |
---|
22 | n/a | sys.stderr.write(file2 + ': cannot change time\n') |
---|
23 | n/a | sys.exit(2) |
---|
24 | n/a | |
---|
25 | n/a | if __name__ == '__main__': |
---|
26 | n/a | main() |
---|