I didn't find anything easy to understand, so I think the content is quite covered, but it's just a memorandum.
Since you can get a generator object in os.walk, convert it to a list for easy handling
dir = list(os.walk("path"))
For some reason, I want to display it on os.walk, but I wanted to know the structure because I want to get the path. What you can get
('root directory', [directory (the directory that appears when you ls)], [file (similarly file)])
It is a list structure that recursively includes the tuple structure. dir [0] has a tuple of the argument path dir [1] has the first tuple structure in the directory 、、、 It's like that.
There may be a better way to get the directory or file name, but I couldn't find it even if I searched for it, so I decided to go with this for the time being.
If you have an easier way, I would appreciate it if you could comment.
Recommended Posts