디렉토리검색
Python, 파이썬반응형
import os
def search(dirname):
try:
filenames = os.listdir(dirname)
for filename in filenames:
full_filename = os.path.join(dirname, filename)
if os.path.isdir(full_filename):
search(full_filename)
else:
ext = os.path.splitext(full_filename)[-1]
if ext == '.py':
print(full_filename)
except PermissionError:
pass
search("c:/")
혹은
import os
for (path, dir, files) in os.walk("c:/"):
for filename in files:
ext = os.path.splitext(filename)[-1]
if ext == '.py':
print("%s/%s" % (path, filename))
반응형
'Python, 파이썬' 카테고리의 다른 글
아래한글 ( HWP ) 텍스트 처리 (0) | 2020.02.17 |
---|---|
DJango Debug Toolbar (0) | 2020.02.17 |
DJango 의 장점 (0) | 2020.02.12 |
DJango.ORM (0) | 2020.02.12 |
Django Rest FrameWork (0) | 2020.02.07 |