Files
courses/py3interm/EXAMPLES/os_walk_ex.py
T
2025-05-20 11:57:43 -04:00

20 lines
542 B
Python

#!/usr/bin/env python
"""print size of every python file whose name starts with "m" """
import os
START_DIR = ".." # start in root of student files # <1>
def main():
for currdir, subdirs, files in os.walk(START_DIR): # <2>
for file in files: # <3>
if file.endswith('.py') and file.startswith('m'):
fullpath = os.path.join(currdir, file) # <4>
fsize = os.path.getsize(fullpath)
print("{:8d} {:s}".format(fsize, fullpath))
if __name__ == '__main__':
main()