1. python으로 txt 파일 읽기
import os
file_path = r"파일 경로"
# 파일 열기
with open(file_path, "r", encoding="utf-8") as file:
file_content = file.read()
print(file_content)
2. python으로 폴더명 읽기
import os
main_folder = r"폴더 경로"
for item in os.listdir(main_folder):
sub_folder = os.path.join(main_folder, item) # 폴더경로 + 폴더명
sub_folder2 = os.path.join(item) # 폴더명만
if os.path.isdir(sub_folder):
# print(sub_folder)
print(sub_folder2)
3. python으로 파일 압축 해제 하기
import os
import zipfile
# 폴더 생성
file_path = r'파일경로'
name = r'폴더명'
path = file_path + name
def makedirs(path):
if not os.path.exists(path):
os.makedirs(path)
makedirs(path)
# 압축 해제
file = r'압축파일경로'
zipfile.ZipFile(file).extractall(path)
'Python > 업무자동화' 카테고리의 다른 글
[python] zipfile.ZipFile로 압축 해제 시 오류 (0) | 2024.07.10 |
---|---|
[python] Selenium 웹크롤러 pyinstaller로 실행 파일 만들기 (0) | 2024.04.05 |
[Python] 폴더, 파일, ZIP 파일 목록 출력 (0) | 2024.01.25 |
[Python] Pyinstaller 실행파일 만들기 (0) | 2024.01.24 |
Python Selenium, bs4를 활용한 웹크롤링 (0) | 2024.01.19 |