import os
os.listdir(path) | path의 모든 파일/폴더을 보여줍니다. |
os.walk(path) | path안의 모든 파일에 대하여 디렉토리로 묶어줍니다. |
os.getcwd() | 현재 작업 공간을 보여줍니다. |
os.chdir(path) | path로 작업 공간을 바꿉니다. |
현재 작업공간의 Sub directory까지 모든 파일을 탐색하는 방법
주의사항: 내부적으로 파일이 너무 많은 위치에서 사용시 탐색을 엄청 많이 합니다.
ex) os.walk('C:') 엄청 오래 시간 걸려요.
for dirname, _, filenames in os.walk('/kaggle/input'):
for filename in filenames:
print(os.path.join(dirname, filename))
|
vdv3C:/
os.path
os.path.exists(path) | path가 존재하는지 여부를 확인해준다. |
os.path.dirname(path) | path의 디렉토리 이름만 알려준다. |
os.path.basename(path) | path의 파일 이름만 알려준다. |
os.path.abspath(path) | 상대주소를 절대주소로 바꿔준다. |
os.path.split(path) | path의 (디렉토리 이름, 파일이름) 알려준다. |
os.path.splitext(path) | path의 (파일이름, 확장자)를 알려준다. |
'프로그래밍' 카테고리의 다른 글
[DP 14501] 퇴사 파이썬 풀이 (1) | 2020.07.13 |
---|---|
[Recursive 14503] 로봇청소기 파이썬 풀이 (0) | 2020.07.12 |
[백준 1541 파이썬 ] Greedy Algorithm 4 - 잃어버린 괄호 (0) | 2020.07.09 |
[백준 11399 파이썬 ] Greedy Algorithm 3 - ATM (0) | 2020.07.09 |
[백준 1931 파이썬 ] Greedy Algorithm 2 - 회의실 배정 (0) | 2020.07.09 |