파이썬 32

python :: 파이썬 zipfile 로 파일 압축하기(하위폴더 포함/미포함) & 압축 해제하기

파이썬에서 파일 압축 & 압축 해제는 zipfile 라이브러리를 사용한다. C:\test └ directory1 └ file4.txt └ file1.txt └ file2.txt └ file3.txt 위 구조에서 C:\test 아래에 있는 txt 파일들을 압축해보기로 한다. 이 때, test 폴더 안의 txt 파일만 압축하려면 os.listdir 을, test 폴더 내 모든 하위폴더 아래에 있는 txt 파일을 다 압축하려면 os.walk 를 사용한다. * 참고: https://toramko.tistory.com/2 python * os.listdir과 os.walk (파이썬 특정 경로 내 디렉토리와 파일 검색) 다음과 같이 폴더와 파일을 생성해두었다. C:\test └ directory1 └ file4.t..

:: python 2021.06.15

python :: os.listdir과 os.walk (파이썬 특정 경로 내 디렉토리와 파일 검색)

다음과 같이 폴더와 파일을 생성해두었다. C:\test └ directory1 └ file4.txt └ file1.txt └ file2.txt └ file3.txt 1. os.listdir os.listdir(path) 특정 경로 내에 존재하는 폴더(디렉토리)와 파일 리스트를 검색 (1-depth) import os file_path = 'C:\\test' for file in os.listdir(file_path): print(file) 위와 같이 작성한 후 실행시키면 directory1 file1.txt file2.txt file3.txt 이렇게 출력된다. directory1 폴더 아래의 file4.txt 는 출력되지 않는다. 2. os.walk os.walk(path) 특정 경로 내에 존재하는 폴더..

:: python 2021.06.14
300x250