<aside> <img src="/icons/list-indent_gray.svg" alt="/icons/list-indent_gray.svg" width="40px" />

目次:

</aside>

参考資料


Pythonでファイル、ディレクトリ(フォルダ)のサイズを取得 | note.nkmk.me

Examples

あるディレクトリ内のディレクトリ名がマッチするディレクトリのフルパスを取得

Python 3.5 : os.scandir

import os
import re

_root= <path>
re.compile(r'^v\d+_')

_result = [_entry.path for _entry in os.scandir(_root)
               if _entry.is_dir() and _pattern.match(_entry.name)]

Python3.4以前(Python3.5より前): os.listdir()

import os

_root= <path>
re.compile(r'^v\d+_')

_result = []
for _dirname in os.listdir(_root):
		_fullpath = os.path.join(_root, _dirname)
		if os.path.isdir(_fillpath) and _pattern.match(_dirname)
				_result.append(_fullpath)