본문 바로가기

Python

[Python] Errno 2 : No such File or Directory 해결 방법

Errno 2 : No such File or Directory 해결 방법

설정 path가 어떨때 가끔 다른 directory 로 이동되는 경우가 발생한다. (특히 생성 후 파일을 이동한 경우 자주 발생)

import os

# Get the current working directory (cwd)
currentPath = os.getcwd()

이를 통해 현재 프로그램에서 포인팅하고 있는 directory를 확인할 수 있게 된다.

 

그러면, 그 directory를 어떻게 바꾸냐? os.chdir("변경할 path") 를 통해 포인팅하는 directory를 바꾸면 끝.

# change path
os.chdir("변경할 path")

# change path (하위 폴더일 경우 유용)
os.chdir(currentPath+"/하위 폴더")

정상적으로 작동하게 된다.