당신은 당신이 (os.listdir 사용하는 15.1. os — Miscellaneous operating system interfaces을보고 귀하의 경우 10.1. os.path — Common pathname manipulations
을 할 수 있습니다 path), 지정된 폴더에있는 모든 파일 목록을 반환합니다.
import os
path = "C:/home/me/data/picture" # full path to folder
# You can print the number of the file in the folder with
# the functions len() and os.listdir()
print(len(os.listdir(path)))
# You can get the list of the files in the folder with:
print(os.listdir(path))
# if you want a more readable outcome, print each file with for loop:
for file in os.listdir(path):
print(file)
더 작업을 위해, 당신은이 기능에보고 할 수 있습니다 :
os.environ(path)을 홈 디렉토리의 경로 이름에 대해. 현재 디렉토리
os.join(path, *paths)를 들어, 디렉토리
os.getcwd()을 변경
os.chdir(path), 가입 경로
및 MKDIR, makedirs 제거와 같은 많은 다른 사람, 을 removedirs 및 경로 조작에서 그 같은 path.basename, path.dirname, path.exist, path.isfile, path.isdir ...
출처
2017-12-13 14:11:50
Gsk
'os.listdir ("some_path")'폴더의 파일 목록을 제공합니다. – DavidG
[Python을 사용하여 각 디렉토리의 한 하위 폴더에서 다른 하위 폴더로 파일을 처리하는 방법은 무엇입니까?] (https://stackoverflow.com/questions/29283466/how-to-process-files-from-one-subfolder-to- another-in-each-directory-using-pytho) – zmo