Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to most efficiently detect file add/delete/rename changes of a directory in Python?

Tags:

python

If I have a table representing paths and sizes of files/subdirectories inside directory A, how can I detect changes recursively in directory A so that I could update my table efficiently?

like image 823
petabyte Avatar asked Nov 26 '13 07:11

petabyte


People also ask

How do you bulk rename files in Python?

To rename files in Python, use the rename() method of the os module. The parameters of the rename() method are the source address (old name) and the destination address (new name).

How do you filter the files by file extensions and show the file names in Python?

To filter and list the files according to their names, we need to use “fnmatch. fnmatch()” and “os. listdir()” functions with name filtering regex patterns. You may find an example of filtering and listing files according to their names in Python.


1 Answers

I use watchdog, which is a python library for just this kind of thing. If you want to know how they're doing it, you can dive into the source code of the project.

like image 68
Games Brainiac Avatar answered Nov 01 '22 13:11

Games Brainiac