Created
November 11, 2016 13:53
-
-
Save Ruhshan/b48a641ab94ce972981ca93ef586eea5 to your computer and use it in GitHub Desktop.
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
import glob | |
import os, time | |
time_and_file=dict() | |
folder_name=raw_input() | |
ct=1 | |
#assuming folder at the same directory as script | |
for filename in glob.glob(folder_name+"/*.*"): | |
name=filename.split('.')[0] | |
try: | |
extension=filename.split('.')[1] | |
except: | |
#sometimes text file may not have extensions | |
extension="" | |
if len(extension): | |
newname=name+"_"+str(ct)+"."+extension | |
else: | |
newname=name+"_"+str(ct) | |
os.rename(filename, newname) | |
ct+=1 | |
access_time=str(time.ctime(os.stat(newname).st_atime)) | |
try: | |
#some files might have been accesse simultaneously thus keeping them in list | |
time_and_file[access_time].append(newname) | |
except: | |
time_and_file[access_time]=[newname] | |
last_access_list=[] | |
for t in sorted(time_and_file.keys()): | |
for name in time_and_file[t]: | |
last_access_list.append(name.replace(folder_name+'/','')) | |
print last_access_list |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment