Skip to content

Instantly share code, notes, and snippets.

@nrtkbb
Created February 17, 2015 10:00
Show Gist options
  • Save nrtkbb/0e4b58fa3ac8cc634d04 to your computer and use it in GitHub Desktop.
Save nrtkbb/0e4b58fa3ac8cc634d04 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- coding=utf-8 -*-
import sys
import os
import subprocess
from datetime import datetime
def exists_check(path):
if not os.path.exists(path):
print(path + ' is not exists. exit.')
sys.exit()
if not os.path.isdir(path):
print(path + ' is not directory. exit.')
sys.exit()
def get_time_stamp(path):
mtime = os.stat(path).st_mtime
return mtime
def touch(path, time_stamp):
dt = datetime.fromtimestamp(time_stamp)
t = dt.strftime('%y%m%d%H%M.%S')
subprocess.call('touch -t {} {}'.format(t, path), shell=True)
if __name__ == '__main__':
# 引数を2つとる。両方共存在していなければプログラム終了
srcdir = sys.argv[1]
dstdir = sys.argv[2]
exists_check(srcdir)
exists_check(dstdir)
for filename in os.listdir(srcdir):
srcpath = os.path.join(srcdir, filename)
if not os.path.isfile(srcpath):
continue
dstpath = os.path.join(dstdir, filename)
if not os.path.isfile(dstpath):
continue
stamp = get_time_stamp(srcpath)
touch(dstpath, stamp)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment