Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 꿀단지스튜디오
- travel
- commit
- 커밋
- svn
- REST
- revision
- pattaya
- Photograph
- snap
- Photo
- 사진
- 체크아웃
- honeyJarStudio
- Street
- 리비전
- 바다
- honeyJar
- Sea
- 파타야
- Thai
- checkout
- 스튜디오
- 여름휴가
- 스냅
- Studio
- 촬영
- 태국
- Thailand
- 여행
Archives
- Today
- Total
꽃무늬 키보드
[python] 디렉토리 전체 탐색, 특정 파일 필터링 본문
특정 디렉토리를 재귀적으로 탐색하여 모든 파일들과 절대경로를 출력
import os pwd = '탐색할 디렉토리 경로' for path, dirs, files in os.walk(pwd): for file in files: print '탐색파일과 절대경로: ' + os.path.join(path, file)
탐색 시, 특정 디렉토리 제외하기 (예: etc 파일 제외)
for path, dirs, files in os.walk(pwd): dirs[:] = [dir for dir in dirs if dir != "etc"]
탐색 시, 특정 파일만 추려내기 (예: 확장자가 .pyc인 파일 추리기)
for path, dirs, files in os.walk(pwd): for file in files: if os.path.splitext(file)[1].lower() == '.pyc': print 'pyc 파일: ' + file
'Programming > python' 카테고리의 다른 글
[Python]ConfigParser사용하여 설정파일 읽어들이기 (5) | 2014.06.26 |
---|---|
정규식_메타문자와 문자열 매칭 (0) | 2014.06.16 |
Comments