Skip to content

FileSizeRange

Bases: BaseFileFilter, FrozenModel

Filter files matching a specified size.

If file size (.stat().st_size) doesn't match the range, it will be excluded. Doesn't affect directories or paths without .stat() method.

Added in 0.13.0

Note

SI unit prefixes means that 1KB == 1 kilobyte == 1000 bytes. If you need 1024 bytes, use 1 KiB == 1 kibibyte.

Parameters:

  • min (int | str) –

    Minimal allowed file size. None means no limit.

  • max (int | str) –

    Maximum allowed file size. None means no limit.

Examples:

Specify min and max file sizes:

from onetl.file.filter import FileSizeRange

file_size = FileSizeRange(min="1KiB", max="100MiB")
Specify only min file size:

from onetl.file.filter import FileSizeRange

file_size = FileSizeRange(min="1KiB")
Specify only max file size:

from onetl.file.filter import FileSizeRange

file_size = FileSizeRange(max="100MiB")

match(path)

Returns True if path is matching the filter, False otherwise

Added in 0.8.0

Examples:

>>> from onetl.impl import LocalPath
>>> filter.match(LocalPath("/path/to/file.csv"))
True
>>> filter.match(LocalPath("/path/to/excluded.csv"))
False
>>> filter.match(LocalPath("/path/to/file.csv"))
True