1. Method Brief Introduction
Os.walk returned is a ternary tupple (Dirpath, Dirnames, filenames),
The first one is the starting path,
The second is a folder under the starting path,
The third one is the file under the starting path.
Dirpath is a string that represents the path to the directory,
Dirnames is a list that contains the names of all subdirectories under Dirpath,
Filenames is a list that contains the name of a non-directory file.
These names do not contain path information, and you need to use Os.path.join (Dirpath, name) if you need to get the full path.
2 attached code: test passed
#!/usr/bin/python# coding:utf-8import osimport os.path#rootdir = "D:\dudu" rootdir= '/home/work/' for parent, Dirnames,filenames in os.walk (RootDir): for dirname in dirnames: print "Parent is:" + parent print "Dirname is" + dirname for filename in filenames: print "Parent is:" + parent print "filename is: " + filename print " The full name of the file is: " + os.path.join (parent,filename) print '-------------'
3 Summary of issues
Python has no results after running
Action: Please check the rootidir path, the reference code for the Linux system.
Python access to file directory