Skip to main content

Fast File Count: Recursively count files and directories very quickly

Project description

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 can be done easily with pip:

pip install ffcount


There is a command line application called ffcount and the package can be used from Python.

The Python package ffcount has only one function: ffcount. 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.


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.

    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.

    files_count : int
        Number of files counted.

    dir_count : int
        Number of directories counted.


This can of course also be obtained by running help(ffcount) in Python.


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.

Files for ffcount, version 0.1.5
Filename, size File type Python version Upload date Hashes
Filename, size ffcount-0.1.5.tar.gz (31.0 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page