본문 바로가기
Informations/python

python에서 특정 폴더에 존재하는 txt파일 가져오기

by 지구별 이용자 2023. 6. 23.
import os
import glob

# 파일을 찾을 경로
path = '/경로/여기에/파일을/찾을/폴더'

# 해당 경로에서 확장자가 ".txt"인 파일 목록 가져오기
files = glob.glob(os.path.join(path, '*.txt'))

file_list = []

# 파일 목록 출력
for file in files:
    file_list.append(file)

os와 glob 를 사용하면 된다!