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.
.. versionadded:: 0.13.0
.. note::
`SI unit prefixes <https://en.wikipedia.org/wiki/Byte#Multiple-byte_units>`_
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.
Nonemeans no limit. -
max(int | str) –Maximum allowed file size.
Nonemeans no limit.
Examples:
Specify min and max file sizes:
.. code:: python
from onetl.file.filter import FileSizeRange
file_size = FileSizeRange(min="1KiB", max="100MiB")
Specify only min file size:
.. code:: python
from onetl.file.filter import FileSizeRange
file_size = FileSizeRange(min="1KiB")
Specify only max file size:
.. code:: python
from onetl.file.filter import FileSizeRange
file_size = FileSizeRange(max="100MiB")
match(path)
¶
Returns True if path is matching the filter, False otherwise
.. versionadded:: 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