Os.walk (Top, Topdown=true, Onerror=none, Followlinks=false)
Can get a ternary tupple (Dirpath, Dirnames, filenames),
The first is the starting path, the second is the folder under the starting path, and the third 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.
Auto-complete recursive enumeration with a for loop
For example:
The F:\AAA directory is such a file directory structure
F:\aaa
|--------1.txt
|--------2.txt
|--------3.txt
|--------4
|-------5.txt
|-------6.txt
|-------7.txt
Os.walk (Top, Topdown=true, Onerror=none, Followlinks=false) can get a ternary tupple (Dirpath, Dirnames, filenames), the first one for the starting path, The second is the folder under the starting path, and the third one is the file under the starting path. Dirpath is a string that represents the path to the directory, and 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 if you need to get the full path, you need to use Os.path.join (Dirpath, name). Auto-complete recursive enumeration via for loop for example: F:\aaa directory is such a file directory structure f:\aaa|--------1.txt| --------2.txt|--------3.txt|--------4 |-------5.txt |-------6.txt |-------7.txt
os.walk (Top, Topdown=true, Onerror=none, Followlinks=false) can get a ternary tupple ( Dirpath, Dirnames, filenames), the first is the starting path, the second is the folder under the starting path, and the third is the file under the starting path. Dirpath is a string that represents the path to the directory, and 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 if you need to get the full path, you need to use Os.path.join (Dirpath, name). Auto-complete recursive enumeration via for loop for example: F:\aaa directory is such a file directory structure f:\aaa|--------1.txt| --------2.txt|--------3.txt|--------4 |-------5.txt |-------6.txt |-------7.txt
Os.walk (Top, Topdown=true, Onerror=none, Followlinks=false) can get a ternary tupple (Dirpath, Dirnames, filenames), the first one for the starting path, The second is the folder under the starting path, and the third one is the file under the starting path. Dirpath is a string that represents the path to the directory, and 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 if you need to get the full path, you need to use Os.path.join (Dirpath, name). Auto-complete recursive enumeration via for loop for example: F:\aaa directory is such a file directory structure f:\aaa|--------1.txt| --------2.txt|--------3.txt|--------4 |-------5.txt |-------6.txt |-------7.txt
The use and examples of Python Os.walk