Updated: 05 mrt 2026
checks the size of files and returns path and size
import os
import argparse
def find_large_files(root_dir, greater_than_size):
results = []
for dirpath, dirnames, filenames in os.walk(root_dir):
for filename in filenames:
full_path = os.path.join(dirpath, filename)
try:
size = os.path.getsize(full_path)
if size > greater_than_size:
relative_path = os.path.relpath(full_path, root_dir)
results.append((relative_path, size))
except OSError:
# Skip files that cannot be accessed
pass
return results
def main():
parser = argparse.ArgumentParser(description="Find files larger than a specified size")
parser.add_argument("directory", help="Root directory to scan")
parser.add_argument("greater_than_size", type=int, help="Minimum file size in bytes")
args = parser.parse_args()
files = find_large_files(args.directory, args.greater_than_size)
for path, size in files:
print(f"{path}\t{size} bytes")
print(f"\nFound {len(files)} files larger than {args.greater_than_size} bytes")
if __name__ == "__main__":
main()