Iterating through the contents of a directory finds both the files and directories contained within a path.
Solution for How to iterate through the contents of a directory in Python : You can use pathlib.Path.iterdir() to iterate through the contents of a directory Call pathlib.Path(directory).iterdir() to list the contents of directory. Use a for-loop to iterate through the contents.