#!/usr/bin/env python3 # -*- coding: utf-8 -*- import os import glob import timeit def walk(dir, exts): result = [] for path, dirs, files in os.walk(os.path.join(dir, '.')): for file in files: #print(file) if file.lower().endswith(exts): dir_path = os.path.abspath(path) result.append(os.path.join(dir_path, file)) return result def main(): # timeit monkey-patching timeit.template = """ def inner(_it, _timer{init}): {setup} _t0 = _timer() for _i in _it: retval = {stmt} _t1 = _timer() return _t1 - _t0, retval """ num_of_exec = 10 dir = r'\\GL-AR750S\sd128gb\dlna' # 拡張子は小文字で定義 !! #exts = ('.mp3', '.m4a', '.wav', '.wma', '.mpg', '.mov', '.mkv', '.mp4', '.webm') exts = ('.mp3', '.m4a', '.flac', '.wav') sec_and_retval = timeit.timeit(lambda: walk(dir, exts), number=num_of_exec) print('{} sec count: {}'.format(sec_and_retval[0] / num_of_exec, len(sec_and_retval[1]))) if __name__ == '__main__': main()