본문 바로가기
프로그래밍/python

python 디렉토리내부 파일리스트 가져오기

by 긱플레이어 2010. 11. 24.

특정 패턴을 적용해서 ( *.* )
디렉토리 내부에서 파일 리스트를 뽑아주는 함수.



##########################################################################
#-*- coding: cp949 -*-
import os
import glob
def searchPatternIncludeSub(dir,patternStr):

    # 우선 지금 폴더의 패턴 검색 해서 저장.
    retlist = glob.glob(os.path.join(dir, patternStr))

    # 하위 디렉토리 검색
    findlist = os.listdir(dir)
    for f in findlist:
        next = os.path.join(dir, f)
        if os.path.isdir(next):
            retlist += searchPatternIncludeSub(next,patternStr)
           
    return retlist
##########################################################################

댓글