Skip to main content

Fast File Count: Recursively count files and directories very quickly

Project description

Fast File Count in Python

This is a Python package to quickly count the number of files and directories in a given path. Optionally you can count recursively and include hidden files in the total.

This package is a wrapper around fast-file-count by Christopher Schultz . Credit for the initial version belongs to Christopher Schultz, I wrote the Python wrapper, converted the Windows code to use builtin functionality, and packaged it up. See the file src/c_count.c for the other contributors and see the commit history of this package on GitHub for my exact changes.

Installation

Installation can be done easily with pip:

$ pip install ffcount

Usage

There is a command line application called ffcount, which recursively counts files and directories:

$ ffcount

See ffcount -h for options.

The package can also be used as a Python library, using the ffcount function. This function returns a tuple (number_of_files, number_of_dirs) and it can be used as follows:

>>> from ffcount import ffcount

# count everything under the current path
>>> ffcount()
(521013, 43012)

# count without hidden files
>>> ffcount(hidden=False)
(234012, 12082)

# use a different path
>>> ffcount('/tmp')
(81, 10)

Note that ffcount counts links as files, even if they point to a directory. In some cases, this explains the discrepancy with other ways of counting.

Docs

The full documentation of the ffcount function is:

def ffcount(path='.', recursive=True, hidden=True, quiet=True):
    """Fast file count

    Count the files and directories in the given path. By default the function
    is recursive and does not print errors. This function uses the C
    implementation by Christopher Schultz.

    Parameters
    ----------
    path : str or bytes
        The path where to start counting. By default the current working
        directory will be used.

    recursive : bool
        To recurse or not to recurse. If recurse is False, only the files and
        directories in the directory given by ``path`` will be counted.

    hidden : bool
        Count hidden files and directories as well.

    quiet : bool
        Don't print errors to the screen. If True, the function will fail 
        quietly and not print any errors.

    Returns
    -------
    files_count : int
        Number of files counted.

    dir_count : int
        Number of directories counted.

    """

License

The original C code by Christopher Schultz was licensed under the Apache License 2.0. This package is therefore licensed under this license as well.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ffcount-0.1.7.tar.gz (27.1 kB view hashes)

Uploaded Source

Built Distributions

ffcount-0.1.7-cp39-cp39-win_amd64.whl (22.3 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

ffcount-0.1.7-cp39-cp39-win32.whl (20.4 kB view hashes)

Uploaded CPython 3.9 Windows x86

ffcount-0.1.7-cp39-cp39-manylinux2010_x86_64.whl (60.5 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.12+ x86-64

ffcount-0.1.7-cp39-cp39-manylinux2010_i686.whl (59.1 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.12+ i686

ffcount-0.1.7-cp39-cp39-manylinux1_x86_64.whl (60.5 kB view hashes)

Uploaded CPython 3.9

ffcount-0.1.7-cp39-cp39-manylinux1_i686.whl (59.1 kB view hashes)

Uploaded CPython 3.9

ffcount-0.1.7-cp39-cp39-macosx_10_9_x86_64.whl (18.5 kB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

ffcount-0.1.7-cp38-cp38-win_amd64.whl (22.2 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

ffcount-0.1.7-cp38-cp38-win32.whl (20.3 kB view hashes)

Uploaded CPython 3.8 Windows x86

ffcount-0.1.7-cp38-cp38-manylinux2010_x86_64.whl (60.2 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.12+ x86-64

ffcount-0.1.7-cp38-cp38-manylinux2010_i686.whl (58.9 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.12+ i686

ffcount-0.1.7-cp38-cp38-manylinux1_x86_64.whl (60.2 kB view hashes)

Uploaded CPython 3.8

ffcount-0.1.7-cp38-cp38-manylinux1_i686.whl (58.9 kB view hashes)

Uploaded CPython 3.8

ffcount-0.1.7-cp38-cp38-macosx_10_9_x86_64.whl (18.5 kB view hashes)

Uploaded CPython 3.8 macOS 10.9+ x86-64

ffcount-0.1.7-cp37-cp37m-win_amd64.whl (22.1 kB view hashes)

Uploaded CPython 3.7m Windows x86-64

ffcount-0.1.7-cp37-cp37m-win32.whl (20.2 kB view hashes)

Uploaded CPython 3.7m Windows x86

ffcount-0.1.7-cp37-cp37m-manylinux2010_x86_64.whl (59.0 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.12+ x86-64

ffcount-0.1.7-cp37-cp37m-manylinux2010_i686.whl (57.7 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.12+ i686

ffcount-0.1.7-cp37-cp37m-manylinux1_x86_64.whl (59.0 kB view hashes)

Uploaded CPython 3.7m

ffcount-0.1.7-cp37-cp37m-manylinux1_i686.whl (57.7 kB view hashes)

Uploaded CPython 3.7m

ffcount-0.1.7-cp37-cp37m-macosx_10_9_x86_64.whl (18.4 kB view hashes)

Uploaded CPython 3.7m macOS 10.9+ x86-64

ffcount-0.1.7-cp36-cp36m-win_amd64.whl (22.1 kB view hashes)

Uploaded CPython 3.6m Windows x86-64

ffcount-0.1.7-cp36-cp36m-win32.whl (20.1 kB view hashes)

Uploaded CPython 3.6m Windows x86

ffcount-0.1.7-cp36-cp36m-manylinux2010_x86_64.whl (58.0 kB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.12+ x86-64

ffcount-0.1.7-cp36-cp36m-manylinux2010_i686.whl (56.6 kB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.12+ i686

ffcount-0.1.7-cp36-cp36m-manylinux1_x86_64.whl (58.0 kB view hashes)

Uploaded CPython 3.6m

ffcount-0.1.7-cp36-cp36m-manylinux1_i686.whl (56.6 kB view hashes)

Uploaded CPython 3.6m

ffcount-0.1.7-cp36-cp36m-macosx_10_9_x86_64.whl (18.4 kB view hashes)

Uploaded CPython 3.6m macOS 10.9+ x86-64

ffcount-0.1.7-cp35-cp35m-win_amd64.whl (22.0 kB view hashes)

Uploaded CPython 3.5m Windows x86-64

ffcount-0.1.7-cp35-cp35m-win32.whl (20.1 kB view hashes)

Uploaded CPython 3.5m Windows x86

ffcount-0.1.7-cp35-cp35m-manylinux2010_x86_64.whl (57.3 kB view hashes)

Uploaded CPython 3.5m manylinux: glibc 2.12+ x86-64

ffcount-0.1.7-cp35-cp35m-manylinux2010_i686.whl (56.0 kB view hashes)

Uploaded CPython 3.5m manylinux: glibc 2.12+ i686

ffcount-0.1.7-cp35-cp35m-manylinux1_x86_64.whl (57.3 kB view hashes)

Uploaded CPython 3.5m

ffcount-0.1.7-cp35-cp35m-manylinux1_i686.whl (55.9 kB view hashes)

Uploaded CPython 3.5m

ffcount-0.1.7-cp35-cp35m-macosx_10_9_x86_64.whl (18.3 kB view hashes)

Uploaded CPython 3.5m macOS 10.9+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page