Reading file metadata
File metadata is everything associated with a particular file that is not the data content itself. The most obvious is the file name, but there are more parameters available such as the size of the file, the creation date, or its permissions.
Browsing through that data is important, for example, to filter files older than a date, or to find all files bigger than a value in KBs. In this recipe, we'll see how to access the file metadata in Python.
Getting ready
We'll use the zen_of_python.txt
file, available in the GitHub repository (https://github.com/PacktPublishing/Python-Automation-Cookbook-Second-Edition/blob/master/Chapter04/documents/zen_of_python.txt). As you can see, by using the ls
command, the file is 856 bytes, and, in this example, it was created on June 14:
$ ls -lrt zen_of_python.txt
-rw-r--r--@ 1 jaime staff 856 14 Jun 21:22 zen_of_python.txt
On your computer, the dates may vary, based on when you downloaded the...