나는 python 플러그인을 notepad ++에 사용하고 있으며 디렉토리의 모든 파일을 출력 할 수 있어야합니다. 기본적으로 명령 프롬프트에서 dir과 같은 것을 실행할 필요가 있습니다.python을 사용하여 디렉토리에있는 모든 파일의 목록을 얻는 방법.
이렇게 할 방법이 있습니까?
나는 python 플러그인을 notepad ++에 사용하고 있으며 디렉토리의 모든 파일을 출력 할 수 있어야합니다. 기본적으로 명령 프롬프트에서 dir과 같은 것을 실행할 필요가 있습니다.python을 사용하여 디렉토리에있는 모든 파일의 목록을 얻는 방법.
이렇게 할 방법이 있습니까?
os.listdir()
함수를 사용하여 디렉토리에있는 파일 목록을 가져올 수 있습니다.
그래서 여기에 모든 파일을 디렉토리에 저장하고 모든 하위 디렉토리를 목록에 넣어서 목록을 출력하는 방법입니다.
참고 : 여기에 발견 된 '거리'방법 :
concatenate the directory and file name
# Task: Get a printout of all the files in a directory.
import os
# The directory that we are interested in
myPath = "https://stackoverflow.com/users/george/documents/"
# All the file paths will be stored in this list
filesList= []
for path, subdirs, files in os.walk(myPath):
for name in files:
filesList.append(os.path.join(path, name))
for i in filesList:
print (str(i))
당신은 의미 ['os.listdir ('.')'] (https://docs.python.org /3/library/os.html#os.listdir)? – abarnert
"a printout"이 의미하는 것이 포맷 된 것을 의미하고'dir'과 같은 추가 컬럼 등이있는 경우, 각각에 대해'os.stat'을 사용하고 컬럼을 직접 포맷팅해야합니다 물론,'subprocess.check_output'을 사용하여 명령 프롬프트의'dir' 명령을 실행할 수도 있습니다. – abarnert