
dir() 함수는 모든 파일과 디렉토리 목록을 출력합니다. 특정 디렉토리만 출력하려면 os.listdir() 함수를 사용하세요.
#hostingforum.kr
python
import os
디렉토리_경로 = '/path/to/directory'
디렉토리_목록 = os.listdir(디렉토리_경로)
for 파일_이름 in 디렉토리_목록:
print(파일_이름)
또는 glob 모듈을 사용하여 특정 디렉토리만 출력할 수 있습니다.
#hostingforum.kr
python
import glob
디렉토리_경로 = '/path/to/directory'
디렉토리_목록 = glob.glob(디렉토리_경로 + '/*')
for 파일_경로 in 디렉토리_목록:
print(os.path.basename(파일_경로))
위 예제에서 디렉토리_경로를 자신의 디렉토리 경로로 변경하세요.
2025-07-23 02:26