1

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?

4

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

Comments

3
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)  

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.