Created
January 15, 2016 01:54
-
-
Save borgle/e5db60a603b026277ca0 to your computer and use it in GitHub Desktop.
有时候需要更改当前目录下所有文件的访问时间和修改时间,当文件过多的时候,可以试试这个小脚本。当然,如果你是工作在linux上,这个可以帮助到你【 find ./ | xargs touch -c -t 201601010000 】
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding:utf8 -*- | |
import time,os,sys | |
newtime = time.time() | |
for root,dirs,files in os.walk(os.path.dirname(__file__)): | |
for name in files: | |
filepath = os.path.join(root, name) | |
os.utime(filepath, (newtime,newtime)) | |
sys.stdout.write(u"\r正在处理 %s...%s" % (filepath.decode('gbk')[:35-len(name)],filepath.decode('gbk')[-len(name)-35:])) | |
sys.stdout.flush() | |
time.sleep(0.01) | |
for name in dirs: | |
folderpath = os.path.join(root, name) | |
os.utime(folderpath, (newtime,newtime)) | |
sys.stdout.write(u"\r正在处理 %s...%s" % (folderpath.decode('gbk')[:35-len(name)],folderpath.decode('gbk')[-len(name)-35:])) | |
sys.stdout.flush() | |
time.sleep(0.01) | |
sys.stdout.write(u"\r全部完成 %s\n" % (' '*75)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment