I have directory with subdirectories and I have to make a list like:
file_name1 modification_date1 path1
file_name2 modification_date2 path2
and write the list into text file how can i do it in python?
I have directory with subdirectories and I have to make a list like:
file_name1 modification_date1 path1
file_name2 modification_date2 path2
and write the list into text file how can i do it in python?
For traversing the subdirectories, use os.walk().
For getting modification date, use os.stat()
The modification time will be a timestamp counting seconds from epoch, there are various methods in the time module that help you convert those to something easier to use.
import os
import time
for root, dirs, files in os.walk('your_root_directory'):
for f in files:
modification_time_seconds = os.stat(os.path.join(root, f)).st_mtime
local_mod_time = time.localtime(modification_time_seconds)
print '%s %s.%s.%s %s' % (f, local_mod_time.tm_mon, local_mod_time.tm_mday, local_mod_time.tm_year, root)