: os.walk()
함수는 3개의 값을 리턴한다.
root
: 현재 탐색 중인 디렉터리(폴더)의 경로dirs
: root
에 있는 하위 디렉터리들의 이름 리스트files
: root
에 있는 파일들의 이름 리스트예를 들어, 아래와 같은 구조의 데이터셋이 있고, os.walk(data_root_path)
을 사용한다면
data_root_path/
├── Training/
│ ├── 01_SourceData/
│ │ ├── file_a.wav
│ │ ├── ...
│ └── 02_LabeledData/
│ ├── file_b.json
│ ├── ...
│
└── Validation/
├── 01_SourceData/
│ ├── file_c.wav
│ ├── ...
└── 02_LabeledData/
├── file_d.json
├── ...
data_root_path
경로의 하위에 있는 모든 디렉토리 경로를 순회한다.
root
는 아래와 같은 순서로 경로를 반환하게된다.
data_root_path/
data_root_path/Training/
data_root_path/Training/01_SourceData/
data_root_path/Training/02_LabeledData/
data_root_path/Training/02_LabeledData/subfolder/
data_root_path/Validation/
data_root_path/Validation/01_SourceData/
data_root_path/Validation/02_LabeledData/
그리고 dirs
에는 현재 위치한 root
의 하위 경로 이름 리스트가 저장된다.
마찬가지로 files
에는 현재 위치한 root
의 파일 이름이 담긴 리스트가 저장된다.