디렉토리의 파일 리스트 가져오기
日新又日新 | 2008. 6. 26. 22:56

디렉토리의 파일 리스트 가져오기

코드

  1. import os
  2. destdir = "c:\\testdir"
  3. #os.chdir(destdir)   #작업 디렉토리를 destdir로 바꾸는 구문.
  4. filelist = os.listdir(destdir)   #destdir의 파일 리스트 가져오기
  5. divider = '.'   #파일 구분자
  6. filetype = 'txt'
  7. for x in filelist:
  8. try:

  9. if x[x.index(divider)+1:] == filetype:   #txt 확장자를 가지는 파일만 출력

  10. print x

  11. except:

  12. pass

 

결과

0.txt
1.txt

 

설명

주석 참조.

이 글은 스프링노트에서 작성되었습니다.


 
 
 
트랙백 | 댓글



위치로그 : 태그 : 방명록 : 관리자
이우성's Blog is powered by Daum / Designed by SSen
관리자  |  글쓰기
BLOG main image
전, 이우성입니다. ( I am Woosung, Lee. ) ""
 Category
 Media
 TAGS
 Recent Entries
 Recent Comments
 Calendar
 Archive
 Link Site
 Visitor Statistics
+ Total :
+ Today :
+ Yesterday :
카피
rss