🔥_Programming/Python2 [Python] 파일 이동, 복사, 삭제 파일작업에 유용한 os 모듈을 소개한다. 예시로 보여드릴 작업 디렉토리의 구조는 다음과 같습니다. ※ 참고 - 디렉토리 구조 그리기: https://jeeuney.tistory.com/19?category=933290 현재 작업위치(working directory) 확인 import os path = os. getcwd() print(path) ▶ D:\TEST 작업위치 변경 import os os.chdir("./test01") #os.chdir("D:/TEST/test01") path = os.getcwd() print(path) ▶ D:\TEST\test01 현재 경로는 "." 으로 간단하게 표현할 수 있다. (os.chdir 명령어를 쓰기 전, 현재 경로는 D:\TEST) 현재 경로의 파일 리스트.. 2022. 4. 22. [Python] 폴더 / 하위 폴더의 파일 탐색 해당 폴더와 그 하위 폴더의 파일들을 전체 탐색 할 수 있는 방법 테스트 폴더의 구성은 아래와 같습니다. C:\TEST │ test3.txt │ ├─test1 │ test4.txt │ test5.txt │ └─test2 │ test6.txt │ test7.txt │ └─test8 test9.txt import os path = r'C:/test' # mother root 입력 file_lst = [] for root, dir, files in os.walk(path) : for file in files : current = os.path.join(root,file).replace('\\','/') file_ls.append(current) if len(current.split('/')) > max_dep.. 2022. 1. 24. 이전 1 다음