Notice
Recent Comments
Link
Tags
- 디지털오션 클라우드서버 생성하기
- C언어
- 클라우드서버 생성
- index 생성
- 디지털오션 드로플릿
- Ubuntu timezone
- 라즈베리파이4
- Python
- 우분투 node js 설치
- ubuntu node js
- 자바 한줄씩 읽기
- express install
- 우분투 시간설정
- node js express install
- npm버전확인
- node 버전확인
- tzselect
- c file read
- Node.js express install
- 파이썬
- mysql index 생성
- 디지털오션 서버생성하기
- 자바 파일 한줄씩 읽기
- node js 버전확인
- c언어 파일 읽기
- 파이썬 반복문
- ubuntu node js install
- java 숫자를 문자로 변환하기
- raspi-config
- 우분투 시간변경
Archives
- Today
- Total
호그래머
Python 폴더 생성 (make directory) 23.01.24 본문
728x90
1. Python 폴더 생성하기
import os 필요
import os
def createFolder(basic_path,dir_name):
try:
if not os.path.exists(basic_path+"/"+dir_name):
os.makedirs(basic_path+"/"+dir_name)
print("폴더 생성 완료!")
else:
print("폴더가 이미 존재합니다!")
except OSError:
print ('폴더생성 에러 발생! ' + basic_path+"/"+dir_name)
dir_path="C:/Users/82105/Desktop"
dir_name="테스트폴더"
createFolder(dir_path, dir_name)
결과
바탕화면에 "테스트폴더" 이름의 폴더가 생성 됩니다.
폴더가 존재하면 이미 존재한다는 메시지를 출력합니다.
끝
1. 파이썬에서 쉽게 폴더를 생성 할 수 있습니다.
2. 폴더를 생성하기전 폴더 유무 파악을 하게됩니다.
3. 폴더를 생성할 경로와 폴더이름을 변수로 지정하였습니다.
728x90
'Python' 카테고리의 다른 글
Python if 사용하기 23.06.26 (0) | 2023.06.27 |
---|---|
Python text 파일 읽기 - 방법1 (파일읽기) 23.06.25 (0) | 2023.06.25 |
Python text 파일 쓰기 - 방법1 (파일쓰기) 23.06.25 (0) | 2023.06.25 |
Python 날짜, 시간표현 (Date, Time) 23.01.24 (0) | 2023.01.24 |
Python 문자열 자르기(substring) 23.01.24 (0) | 2023.01.24 |
Comments