python
OSError: [Errno 66] Directory not empty: 'test_direction'
타닥타닥 토다토닥 부부
2023. 11. 23. 20:29
반응형
OSError: [Errno 66] Directory not empty: 'test_direction'¶
- 터미널에서 아래와 같은 명령어를 입력하면
test_direction아래test_file.txt파일이 있는 것을 확인할 수 있습니다.
In [5]:
!ls -R test_direction
test_file.txt
os.rmdir매서드를 사용할 경우test_direction아래 파일이 하나라도 있으면 아래와 같이 에러가 발생합니다.
In [4]:
import os
os.rmdir("test_direction")
--------------------------------------------------------------------------- OSError Traceback (most recent call last) <ipython-input-4-d99e7fbfb4d3> in <module> 1 import os 2 ----> 3 os.rmdir("test_direction") OSError: [Errno 66] Directory not empty: 'test_direction'
- 만약
test_direction아래 파일 존재 여부를 무시하고 지우려면 아래와 같이shutil.rmtree()메서드를 이용합니다.
In [7]:
import shutil
shutil.rmtree("test_direction")
반응형