0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

使っていない大きなファイルを探すときのために

Last updated at Posted at 2021-05-24

使っていない大きなファイルを探すときのために。

WindowsのCドライブ以下を探す場合を想定しています。

search_big_file.py
import os
import pathlib

def get_path_recursive(path):
    for p in path.iterdir():
        try:
            if p.is_dir():
                get_path_recursive(p)
            elif p.is_file():
                s = os.path.getsize(p)
                if s > 1024*1024*1024:
                    print(f'{s}:{p}')
        except PermissionError:
            print(f'PermissionError:{p}')
        except OSError:
            print(f'OSError:{p}')

path = pathlib.Path('C:\\')
get_path_recursive(path)
0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?