0
출력에 파일 및 폴더 구조를 재귀 적으로 표시하려고합니다.디렉토리에있는 파일을 재귀 적으로 나열 - python
실제 구조 :
Root--|
|
DIRA--|
|
DIRC--File5
File3
File4
File1
File2
DIRB--|
|
No File
예상 출력 : 나는 아래의 다음과 같은 코드를 작성했습니다
Root:
File1
File2
Root/DIRA
File3
File4
Root/DIRA/DIRC
File5
Root/DIRB
No File Found
. 그러나 필요한 출력을 얻으려면 수정하는 방법과 마찬가지로 입력이 필요합니다.
코드
import os.path
path = 'C:\\My\\path\\here'
for root, dirnames, filenames in os.walk(path):
for subdirname in dirnames:
print subdirname
for filename in filenames:
print os.path.join(root, filename)
실제 출력
DIRA
DIRB
C:\My\path\here\File1
C:\My\path\here\File2
DIRC
C:\My\path\here\DIRA\File3
C:\My\path\here\DIRA\File4
C:\My\path\here\DIRA\DIRC\File5
들여 – Jiminion