파일 조작과 시스템 2
파일 조작과 시스템
파일 조작 - 라이브러리
"""
import os
# 파일이 존재하나요 ?
print(os.path.exists('test.txt'))
# 다음이 파일인가요 ?
print(os.path.isfile('test.txt'))
# 다음이 폴더인가요 ?
print(os.path.isdir('test.txt'))
# 파일의 이름 변경
os.rename('test.txt', 'rename.txt')
# 파일끼리 링크걸기(내용 공유)
os.symlink('rename.txt', 'symlink.txt')
# 폴더 생성
os.mkdir('test_dir')
# 폴더 삭제
os.remove('test_dir')
* 폴더 안에 파일 있으면 삭제 불
# 폴더 안에 폴더 검색해서 리스트로 돌려줌
print(os.listdir('test_dir'))
# 현재 위치 출력
print(os.getcwd())
# 폴더 안에 파일 검색해서 리스트로 돌려줌
import glob
print(glob.glob('test_dir/*'))
* 는 전부 표시
# 파일 복사
import shutil
shutil.copy('test_dir/복사할 파일명', 'test_dir/붙여넣기할 파일명')
# 파일이 존재하는 폴더 삭제
import shutil
shutil.rmtree('test_dir')
Author And Source
이 문제에 관하여(파일 조작과 시스템 2), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://velog.io/@sayxyoung/python-syntax-file2
저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
"""
import os
# 파일이 존재하나요 ?
print(os.path.exists('test.txt'))
# 다음이 파일인가요 ?
print(os.path.isfile('test.txt'))
# 다음이 폴더인가요 ?
print(os.path.isdir('test.txt'))
# 파일의 이름 변경
os.rename('test.txt', 'rename.txt')
# 파일끼리 링크걸기(내용 공유)
os.symlink('rename.txt', 'symlink.txt')
# 폴더 생성
os.mkdir('test_dir')
# 폴더 삭제
os.remove('test_dir')
* 폴더 안에 파일 있으면 삭제 불
# 폴더 안에 폴더 검색해서 리스트로 돌려줌
print(os.listdir('test_dir'))
# 현재 위치 출력
print(os.getcwd())
# 폴더 안에 파일 검색해서 리스트로 돌려줌
import glob
print(glob.glob('test_dir/*'))
* 는 전부 표시
# 파일 복사
import shutil
shutil.copy('test_dir/복사할 파일명', 'test_dir/붙여넣기할 파일명')
# 파일이 존재하는 폴더 삭제
import shutil
shutil.rmtree('test_dir')
Author And Source
이 문제에 관하여(파일 조작과 시스템 2), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@sayxyoung/python-syntax-file2저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)