2017-09-25 32 views

答えて

1

私はこれがあなたが欲しいものをやるべきだと思います。

import os 
from os.path import join, getsize 
for root, dirs, files in os.walk('C:/your_path_here/'): 
    print(root, "consumes", end=" ") 
    print(sum(getsize(join(root, name)) for name in files), end=" ") 
    print("bytes in", len(files), "non-directory files") 
2

この@balki

In [39]: from pathlib import Path 

In [40]: def get_siblings(path): 
    ...:  parent = path.parent 
    ...:  for x in parent.iterdir(): 
    ...:   if x.is_dir() and x != path: 
    ...:    yield x 
    ...:    

In [41]: for f in get_siblings(Path.cwd()): 
    ...:  print(f) 
    ...:  
/mnt 
/snap 
/lib 
/bin 
/tmp 
/sbin 
/usr 
/lib64 
/opt 
/lib32 
/boot 
/etc 
/media 
+0

おかげで私のために働いているpathlibモジュールを使用します –

関連する問題