File metadata describes a file beyond its contents. It can help locate related files, check data before processing, or determine when content was modified. section 11.5 section 11.5.2
Common file metadata available through a Path object includes:
- Directory, filename, and extension, useful when constructing paths to related files. section 11.5
- Size in bytes and content modification time, retrievable with stat(); st_mtime can be converted to a readable timestamp with time.ctime(). section 11.5.2
Listing 11.19 Creating a function to screen file sizes
def process_data_using_size_cutoff(min_size, max_size):
data_folder = Path("data")
for dat_path in data_folder.glob("*.dat"):
filename = dat_path.name
size = dat_path.stat().st_size #1
if min_size < size < max_size: #2
print(f"{filename}, Good; {size}, within
[{min_size}, {max_size}]")
else:
print(f"{filename}, Bad; {size}, outside
[{min_size}, {max_size}]")
This example screens experimental data files by size, marking files inside a chosen range as good and others as bad. section 11.5.2




















