아마도 과 os.access
을 조사해야합니다. 당신이 뭔가를 할 수있는 실제 구현을 위해
:
import os
def get_files(path, option_dirs, option_subdirs, option_no_ro, option_no_hid):
outfiles = []
for root, dirs, files in os.walk(path):
if option_no_hid:
# In linux, hidden files start with .
files = [ f for f in files if not f.startswith('.') ]
if option_no_ro:
# Use os.path.access to check if the file is readable
# We have to use os.path.join(root, f) to get the full path
files = [ f for f in files if os.access(os.path.join(root, f), os.R_OK) ]
if option_dirs:
# Use os.path.join again
outfiles.extend([ os.path.join(root, f) for f in files ])
else:
outfiles.extend(files)
if not option_subdirs:
# If we don't want to get subdirs, then we just exit the first
# time through the for loop
return outfiles
return outfiles
의
가능한 중복 (http://stackoverflow.com/questions/3207219/how- [파이썬의 디렉토리의 모든 파일을 나열하는 방법] to-list-all-of-a-python 디렉토리) – ecatmur
링크는 1) 및 2) 옵션에 대한 답변을 보여줍니다. 하지만 RO 및 숨겨진 파일을 제외하는 방법은 무엇입니까? – Prog1020