-
Book Overview & Buying
-
Table Of Contents
Python Automation Cookbook - Third Edition
By :
File metadata is everything associated with a particular file that is not the data content itself. The most obvious piece of metadata is the file name, but others include the size of the file, the creation date, and its permissions.
Browsing through that data may be important, for example, to filter files older than a date, or to find all files bigger than a value in kilobytes. In this recipe, we'll see how to access the file metadata in Python.
We'll use the zen_of_python.txt file, available in the GitHub repository (https://github.com/PacktPublishing/Python-Automation-Cookbook-Third-Edition/blob/main/ch04/documents/zen_of_python.txt). Using the ls command, you can see that the file takes up 823 bytes, and that, in this example, it was created on December 15th:
$ ls -lrt zen_of_python.txt
-rw-r--r--@ 1 jaimebuelta staff 823 15 Dec 15:43 zen_of_python.txt
(On your computer, the dates may vary, depending on when you downloaded the code.)
...