Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 29 | 30 |
Tags
- machine learning
- 파이썬
- 출근 전날
- 인공지능
- 황토펜션
- 하늘숲펜션
- 지리산 펜션
- 산청 황토 펜션
- 파이썬 GUI
- cuda
- 텐서플로 설치
- 계곡 펜션
- 아나콘다 텐서플로
- 오봉 계곡
- tensorflow
- CUDA9.0
- 하늘숲 황토 펜션
- anaconda tensorflow
- 하늘숲황토펜션
- LISP 함수
- 전용 계곡
- ubuntu
- 지리산 둘레길
- python yield
- HTML
- 파이썬 yield
- tensorflow 설치
- LISP
- 지리산 황토 펜션
- Python
Archives
- Today
- Total
YongWook's Notes
<파이썬> 파일명, 경로 변경하기 본문
다음은 파일 일괄처리에 도움이 되는 파이썬의 함수들이다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | os.listdir(path) # 파일목록전달 os.chdir(path) # 작업하고 있는 디렉토리 변경 os.getcwd() # 현재 프로세스의 작업 디렉토리 얻기 os.path.abspath(filename) # 파일의 상대 경로를 절대 경로로 바꾸는 함수 os.path.exists(filename) # 주어진 경로의 파일이 있는지 확인하는 함수 os.curdir() # 현재 디렉토리 얻기 os.pardir() # 부모 디렉토리 얻기 os.sep() # 디렉토리 분리 문자 얻기 os.path.basename(filename) # 파일명만 추출 os.path.dirname(filename) # 디렉토리 경로 추출 os.path.split(filename) # 경로와 파일명을 분리 os.path.join(path,path) # \\패턴으로 경로를 만들어줌 os.path.splitdrive(filename) # 드라이브명과 나머지 분리 (MS Windows의 경우) os.path.splitext(filename) # 확장자와 나머지 분리 shutil.copy(path, newPath) # 파일 복사 shutil.copy2(path, newPath) # 파일 복사 (설정값도 함께 복사) shutil.move(path, newPath) # 파일 이동줌 |
다음은 졸업과제를 진행하면서 CAFFE로 뉴럴네트워크를 학습시킬 때 데이터 전처리에 사용했던 파이썬 코드이다.
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 | import os import shutil pivot = 22 label_num = 14 os.chdir( '/home/nr-lab/Downloads/labeled_images/Label_' + str (label_num) + '/' ) files = os.listdir( '.' ) files.sort() fileNum = [] for file in files: file = file [ len ( 'L' + str (label_num) + '_' ):] file = file .rstrip( '.jpg' ) fileNum.append( int ( file )) fileNum.sort() sortedFile = [] for fn in fileNum: sortedFile.append( 'L' + str (label_num) + '_' + str (fn) + '.jpg' ) for name in sortedFile: if name.startswith( 'L' + str (label_num) + '_' + str (pivot) + '.jpg' ): newname = 'L' + str (label_num - 4 ) + '_' + str (count) + '_test.jpg' os.rename(name, newname) shutil.move( './' + newname, '../test/' + newname) count + = 1 pivot + = 1 |
'-software > python' 카테고리의 다른 글
<파이썬> generator & yield (0) | 2018.12.07 |
---|---|
<WebGL> 그림판 만들기 (0) | 2016.09.30 |
<파이썬> Tkinter - GUI 예제 (4) | 2016.05.30 |
<파이썬> random과 배열, 생태계 개체수 예측하기 (0) | 2016.05.09 |
<파이썬> TKinter - GUI 만들기 (2) | 2016.04.25 |