We can use the os
module in Python to iterate over all the files in a directory (current directory, in this case) and its subdirectories. We can use the os.walk()
function to walk through the directory tree, and for each file, we can print its full path using the os.path.join()
function as shown below:
main.py265 chars11 lines
In the code above, we first set the root_dir
variable to the current directory (i.e., .
). Then, we use the os.walk()
function to traverse through all the directories and subdirectories of the root directory. For each file, we use the os.path.join()
function to concatenate the directory path and file name, and then print the resulting full path.
gistlibby LogSnag