We have been reading data from files, networks, services, and databases. Python can also go through all of the directories and folders on your computers and read those files as well.
In this chapter, we will write programs that scan scan through your computer and perform some operation on each file. Files are organized into directories (also called “folders”). Simple Python scripts can make short work of simple tasks that must be done to hundreds or thousands of files spread across a directory tree or your entire computer.
To walk through all the directories and files in a tree we use os.walk and a for loop. This is similar to how open allows us to write a loop to read the contents of a file, socket allows us to write a loop to read the contents of a network connection, and urllib allows us to open a web document and loop through its contents.