Python | 특정 폴더의 파일 리스트 가져오기
temp
##
# -*- coding: utf-8 -*-
import os
# 가져올 파일들이 있는 directory path
path_dir = '/home/juce/study/tf/tf_org_tutorials/04_cnn/cifar10/cifar10_train'
file_list = os.listdir(path_dir) # path 에 존재하는 파일 목록 가져오기
file_list.sort() # 파일 이름 순서대로 정렬
"""
파일 이름에서 특정 부분 가져오기 예시
"""
# 'model.ckpt-3000' 와 같은 이름을 가진 파일에서 특정 정보를 가져오고 싶다먄
# ckpt.model_checkpoint_path 가 'model.ckpt-3000' 의 값을 가지고 있을 경우
step = int(ckpt.model_checkpoint_path.split('/')[-1].split('-')[-1])
# setp = 3000 이라는 int 값을 가지게 된다.
"""
파일 이름에 특정 string 을 가지는 파일만 뽑아내기
"""
for item in file_list:
# some_string 이 파일 이름에 없을 경우 -1 을 반환
if item.find('some_string') is not -1:
print item # some_string 을 파일이름에 포함하는 파일만 출력
##
temp
'Python > Examples' 카테고리의 다른 글
| Python | Examples | String to datetime (0) | 2016.03.02 |
|---|---|
| Python | Example | convert (encoding/decoding) URL Unicode to UTF-8 characters (0) | 2016.02.26 |
| Python | Examples | xlwt, xlrd, xlutils 사용하기 | python - excel 파일 다루기 (0) | 2016.01.12 |
| Python | Study | 파일 자동으로 filepath 만 주면 directory 까지 만들어서 저장하는 방법 (0) | 2016.01.07 |
| Python | Example | Directory 만들기 | Directory 내 file 존재 유무 확인 (0) | 2015.12.09 |