import os # os 를 import 하고
filename, fileExtension = os.path.splitext('./test.zip')
# 위 코드를 실행하면 filename 에 파일명이, fileExtension 에 확장자명이 들어간다.
# 여기서 확장자명은 . (dot) 을 포함하여 '.zip' 가 저장된다.
파일명만 받아 오고 싶다!? # 뒤에 [0] 을 추가
filename = os.path.splitext('./test.zip')[0]
확장자명만 받아 오겠다!? # 뒤에 [1] 을 추가
filename = os.path.splitext('./test.zip')[1]
하면 됩니다.!
※폴더에서 파일들을 불러오는 것을 더하여 파일명과 확장자 명들을 출력해보고 확장자명 string 비교까지 예
import dircache
import os
list = dircache.listdir('.') # 현재 경로 폴더의 파일들을 불러온다.
for item in list:
filename, fileExtension = os.path.splitext(item)
print '파일명 : ' + filename + ' 확장자명 : ' + fileExtension
if extension in '.zip':
print 'this file type is zip'
'Python' 카테고리의 다른 글
Facebook Network에서 Community Detection (0) | 2013.06.15 |
---|---|
사회관계망 네트워크의 상호성 및 팔로어 수/친구 수 분포 분석 (0) | 2013.04.29 |
python 디렉토리(폴더) 안애 파일 목록 불러오기 (0) | 2013.04.04 |
python 스트링 값 비교 ( string compare) (0) | 2013.04.04 |
Twitter, Facebook 소셜 그래프 특성 분석 (0) | 2013.03.28 |