[ Python ] 파이썬 하위 디렉토리 및 파일 전체 검색 방법

[ Python ] 파이썬 하위 디렉토리 및 파일 전체 검색 방법



1. 코드

import os

StartPath = os.path.dirname
        ("/home/heojungwook/다운로드/SideLog/")
print(StartPath)

for NowPath in os.walk(StartPath):
#NowPath[0] = 현재 위치
print(NowPath[0])
#NowPath[1] = 현재 위치의 폴더
for FileName in NowPath[1]:
print(FileName)
#NowPath[2] = 현재 위치의 파일
for FileName in NowPath[2]:
print(FileName)


2. 디버깅




3. 출력

/home/heojungwook/다운로드/SideLog
/home/heojungwook/다운로드/SideLog SideLog TopMapLog PRSLog /home/heojungwook/다운로드/SideLog/SideLog 2017Y /home/heojungwook/다운로드/SideLog/SideLog/
    2017Y
11M /home/heojungwook/다운로드/SideLog/SideLog/
    2017Y/11M 12D 10D 09D 13D 11D /home/heojungwook/다운로드/SideLog/SideLog/
    2017Y/11M/12D 123 TopMapResultLog.txt /home/heojungwook/다운로드/SideLog/SideLog/
    2017Y/11M/12D/123 TopMapResultLog.txt /home/heojungwook/다운로드/SideLog/SideLog/
    2017Y/11M/10D TopMapResultLog.txt /home/heojungwook/다운로드/SideLog/SideLog/
    2017Y/11M/09D TopMapResultLog.txt /home/heojungwook/다운로드/SideLog/SideLog/
    2017Y/11M/13D 20_QFN_3X3 BtmSideResultLog.txt TopMapResultLog.txt /home/heojungwook/다운로드/SideLog/SideLog/
    2017Y/11M/13D/20_QFN_3X3 20h03m22s159ms_ENLeadLength_M0S4.BMP 20h03m22s159ms_ENLeadLength_M0S5.BMP 20h03m22s159ms_ENLeadLength_M0S0.BMP 20h03m22s159ms_ENLeadPitch_M0S1.BMP /home/heojungwook/다운로드/SideLog/SideLog/
    2017Y/11M/11D TopMapResultLog.txt /home/heojungwook/다운로드/SideLog/TopMapLog 2017Y /home/heojungwook/다운로드/SideLog/TopMapLog/
    2017Y 11M /home/heojungwook/다운로드/SideLog/TopMapLog/
    2017Y/11M 12D 10D 09D 13D 11D /home/heojungwook/다운로드/SideLog/TopMapLog/
    2017Y/11M/12D TopMapResultLog.txt /home/heojungwook/다운로드/SideLog/TopMapLog/
    2017Y/11M/10D TopMapResultLog.txt /home/heojungwook/다운로드/SideLog/TopMapLog/
    2017Y/11M/09D TopMapResultLog.txt /home/heojungwook/다운로드/SideLog/TopMapLog/
    2017Y/11M/13D TopMapResultLog.txt /home/heojungwook/다운로드/SideLog/TopMapLog/
    2017Y/11M/11D TopMapResultLog.txt /home/heojungwook/다운로드/SideLog/PRSLog 2017Y /home/heojungwook/다운로드/SideLog/PRSLog/
    2017Y 11M /home/heojungwook/다운로드/SideLog/PRSLog/
    2017Y/11M 12D 10D 09D 13D 11D /home/heojungwook/다운로드/SideLog/PRSLog/
    2017Y/11M/12D TopMapResultLog.txt /home/heojungwook/다운로드/SideLog/PRSLog/
    2017Y/11M/10D TopMapResultLog.txt /home/heojungwook/다운로드/SideLog/PRSLog/
    2017Y/11M/09D TopMapResultLog.txt /home/heojungwook/다운로드/SideLog/PRSLog/
    2017Y/11M/13D 20_Test 7777 TopMapResultLog.txt BtmPRSDimension.txt BtmPRSResultLog.txt /home/heojungwook/다운로드/SideLog/PRSLog/
    2017Y/11M/13D/20_Test 20h03m25s455ms_ENDistance_M0S5.BMP 20h03m19s039ms_ENDistance_M0S2.BMP 20h03m25s455ms_ENDust_M0S3.BMP 20h03m19s039ms_ENDistance_M0S7.BMP 20h03m19s039ms_ENDistance_M0S1.BMP 20h03m19s039ms_ENDistance_M0S5.BMP 20h03m25s455ms_ENDust_M0S1.BMP 20h03m25s455ms_ENDistance_M0S0.BMP 20h03m19s039ms_ENDistance_M0S3.BMP 20h03m25s455ms_ENDistance_M0S7.BMP 20h03m19s039ms_ENDistance_M0S0.BMP 20h03m25s455ms_ENDistance_M0S6.BMP 20h03m19s039ms_ENDistance_M0S4.BMP 20h03m25s455ms_ENDistance_M0S2.BMP 20h03m25s455ms_ENDistance_M0S4.BMP 20h03m19s039ms_ENDistance_M0S6.BMP /home/heojungwook/다운로드/SideLog/PRSLog/
    2017Y/11M/13D/7777 19h39m22s538ms_ENDust_M0S3.BMP 19h39m22s538ms_ENBurrBetweenLeads_M0S1.BMP /home/heojungwook/다운로드/SideLog/PRSLog/
    2017Y/11M/11D TopMapResultLog.txt




댓글