Tell me the code that lists all the files in a given drive / folder with extensions, size and date of change / save is needed for further tracking changes in the directory.
while it happened

# -*- coding: utf-8 -*- import os path_f = [] file1 = open('1.txt', "w") for d, dirs, files in os.walk(u'd:'): for f in files: path = os.path.join(d,f) path_f.append(path) file1.write(str(path_f)) file1.close() 

It remains to figure out how to add the size and the date of saving / changing to each file.

  • Google in the direction of the standard library "os". In particular, the following functions may be useful to you: os.walk - a generator of the list of directories and files within a given directory. os.path.getmtime - returns the time when the file was last modified os.path.getsize - returns file size - Xander
  • 3
    It looks like an XY task . Clarify the question. What changes do you want to track? Try the watchdog module . - jfs
  • one
    You need a walk and stat from the os module. - 0andriy
  • Do you happen to be looking for it? - MaxU

2 answers 2

 # -*- coding: UTF-8 -*- from os import path, listdir from time import ctime folder = 'libs' for name in listdir(folder): full_name = path.join(folder, name) if path.isfile(full_name): name_, _ext = path.splitext(name) time_info = [ctime(fn(full_name)) for fn in (path.getatime, path.getmtime, path.getctime)] file = { 'каталог': folder, 'файл': full_name, 'файл_имя': name_, 'файл_расширение': _ext, 'время последнего доступа': time_info[0], 'время последнего изменения': time_info[1], 'время создания': time_info[2], } print('\n'.join('{:<30} : {}'.format(*f) for f in sorted(file.items())), '\n') 

out:

 время последнего доступа : Sun Jan 22 16:41:03 2017 время последнего изменения : Sun Jan 22 16:41:03 2017 время создания : Sun Jan 22 16:41:03 2017 каталог : libs файл : libs\log.py файл_имя : log файл_расширение : .py время последнего доступа : Sun Jan 22 23:08:33 2017 время последнего изменения : Sun Jan 22 23:08:33 2017 время создания : Sun Jan 22 23:08:33 2017 каталог : libs файл : libs\trace_dec.py файл_имя : trace_dec файл_расширение : .py ... 
  • os.scandir() can be used as a more readable and effective solution to get a list of files with meta data. Here are a couple of examples - jfs
  • @vadim vaduxa Just now I saw that your example is not collecting data from subfolders - Alexander Kudryavtsev

The standard glob module should help

 from glob import glob fileslist = glob("путь к диску/**/*") 

** - means all directories recursively, * - all files

Time changes and more can be requested through os.stat()

  • ** does not have a special meaning if recursive=True not passed. - jfs
  • but it works without - eri
  • try with nested directories to ensure that recursive behavior does not work without an explicit flag. - jfs