파일의 개수를 구해야 하는 순간에 쓰는 Python 코드입니다.
os.listdir()을 이용하여 폴더 안에 있는 파일들의 list를 가져온 후, list의 길이를 측정하는 방식으로 폴더 안의 파일의 개수를 구할 수 있습니다.
import os
folder_path = "/desktop/example/"
file_list = os.listdir(folder_path)
fileNumber = len(file_list)
print(fileNumber)
'Python' 카테고리의 다른 글
| List란? (1) | 2024.03.06 |
|---|---|
| 인덱스와 배열값을 같이 가져오는 Enumerate() (0) | 2024.02.21 |
| argparse ( 명령행 인자 Parsing ) (3) | 2024.01.18 |
| Python - os 모듈 ( listdir,mkdir,join,getcwd,exists,walk ) (3) | 2024.01.17 |