Python os related files, subdirectory operations

Get Python directory name

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

Python os related files, subdirectory operations
About Python and os operations
python related summary
My os (python)
File operations in Python
[Python] File / directory operations
File operations in Python
Python iteration related summary
Python> library> os> link related> os.link () / os.readlink () / os.symlink () / os.unlink ()
Python --Tagging MP3 files
[Python] Reading CSV files
Summary of python file operations
Four arithmetic operations in python
Various Python built-in string operations
Sorting image files with Python (2)
Sort huge files with python
Sorting image files with Python (3)
Sorting image files with Python
Integrate PDF files with Python
Reading .txt files with Python
Wrapping git operations in Python
Decompress multiple compressed files (Python)
Platform (OS) determination by Python