python3.4 The file directory, do not need to deal with the special Chinese code
Use Os.walk to traverse Chinese catalogs directly.
The Os.walk method returns 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.
The above is a practical introduction to the Python os.walk traversal directory.
__author__='Administrator'ImportOSPrint(os.sep) path="d:\ working Directory"+Os.sepPrint(PATH)Print(Os.walk (path)) forRoot,dirs,filesinchOs.walk (path):Print(Root) forFileinchFiles:ifRoot = =Path:Print(root+file)Else: Print(root+os.sep+file) forDirNameinchdirs:Print(Root+dirname)
Access to all files through traversal of the root path
python3.4 The file directory, do not need to deal with the special Chinese code