{"id":15397023,"url":"https://github.com/ryanhefner/file-counter","last_synced_at":"2026-05-15T18:02:51.680Z","repository":{"id":57235448,"uuid":"88914544","full_name":"ryanhefner/file-counter","owner":"ryanhefner","description":"Calculate the number of files within a directory and its subdirectories. Apply rules to filter files or directories from the total.","archived":false,"fork":false,"pushed_at":"2017-05-23T15:00:25.000Z","size":36,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"develop","last_synced_at":"2025-02-02T02:14:26.367Z","etag":null,"topics":["cli","command-line-tool","filesystem","nodejs","utility"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ryanhefner.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-04-20T22:07:16.000Z","updated_at":"2023-02-13T19:32:09.000Z","dependencies_parsed_at":"2022-09-15T06:40:51.324Z","dependency_job_id":null,"html_url":"https://github.com/ryanhefner/file-counter","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryanhefner%2Ffile-counter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryanhefner%2Ffile-counter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryanhefner%2Ffile-counter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryanhefner%2Ffile-counter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ryanhefner","download_url":"https://codeload.github.com/ryanhefner/file-counter/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245944109,"owners_count":20697960,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cli","command-line-tool","filesystem","nodejs","utility"],"created_at":"2024-10-01T15:35:51.410Z","updated_at":"2025-10-29T12:40:05.794Z","avatar_url":"https://github.com/ryanhefner.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# file-counter\nRecursively counts the number of files within a directory, and all of its subdirectories.\nApply filters to exclude files or directories from the total.\n\n## Install\n`file-counter` can be used as either a command line utility or included in your\nprojects or scripts where you need to know the number of files within a directory.\n\n### CLI\nInstall globally so you can run the `file-counter` command via the command line\nwithin a directory to get the total number of files within that directory and all\nsub-directories.\n\nVia [npm](https://www.npmjs.com):\n\n`npm install -g file-counter`\n\n### `countFiles` Method\nIf you need to get the total number of files for a task progress bar, or you’re\nevaluating the number of files within a directory for maintenance purposes within\nanother script, you can use the `countFiles` method.\n\nVia [npm](https://www.npmjs.com):\n\n`npm install file-counter`\n\nVia [yarn](https://yarnpkg.com):\n\n`yarn add file-counter`\n\n## How to use\nYou can use `file-counter` two different ways, as a command line utility or as a\nutility for use within your package or project. Below are a few examples on how\nyou can use it in those scenarios.\n\n### CLI\n\n\n```\n$ file-counter [options] [dir]\n```\n\n#### Options\nThe following options are available both for the CLI use of `file-counter`, as\nwell as for the `countFiles` method. Please note that when using the `--exclude-*`,\nor `excludeDirs`, options that the defaults will no longer be applied.\n\n##### Exclude Files - `-f, --exclude-files [...files]`\nDepending on what you’re doing, you may find the need to exclude certain files\nfrom the total that is returned. You can do that by including a comma separated\nlist of file names or regular expressions to exclude from the count tally.\n\nBy default, the following files are excluded from totals:\n\n* `.DS_Store`\n* `.DS_Store?`\n* `.Spotlight-V100`\n* `.Trashes`\n* `ehthumbs.db`\n* `Thumbs.db`\n\nHere’s an example of using the `-f`, or `--exclude-files`, option:\n\nExlude any `.DS_Store` file and all Javascript (`*.js`) files:\n```\n$ file-counter -f '.DS_Store,(.*).js'\n```\n\n##### Exclude Directories - `-d, --exclude-dirs [...directories]`\nThe same goes for directories. You can use either the exact directory name or a\nregular expression to exclude directories, and their files, from being included\nin the total count.\n\nBy default, the following directories are excluded from totals:\n\n* `.git`\n* `node_modules`\n* `vendor`\n\nHere are a few examples of using the `-d`, or `--exclude-dirs`, option:\n\nExclude `.git` and `node_modules` directories:\n```\n$ file-counter -d '.git,node_modules'\n```\n\nExclude all directories (ie. only tally the files in the root directory):\n```\n$ file-counter -d '(.*)'\n```\n\n##### Verbose - `-v, --verbose`\nIncluding the `--verbose` flag will output file names included in the total count.\n\n```\n$ file-counter -v\n```\n\n### `countFiles` Method\nIn addition to the command line utility, you can also use the method that the\nutility relies on in your own projects and scripts where you would want to know\nthe number of files in a directory.\n\n```\ncountFiles({...options}, count = 0)\n```\n\n*__Note:__ `count` is there because the method is recursively called while traversing\nthe directories. Please do _not_ prepopulate that argument unless you want to\nincrement/decrement the count by that value.\n\n#### Options\n\n```\ncountFiles({\n    dir: '...',\n    excludeFiles: ['...',],\n    excludeDirs: ['...',],\n    includeLogs: [true|false],\n    verbose: [true|false],\n})\n```\n\nHere’s an example where we use the `countFiles` method in combination with the\n[progress](https://github.com/visionmedia/node-progress) package to show a progress\nbar during the processing of a Node script.\n\n```\nimport path from 'path';\nimport { countFiles } from 'file-counter';\nimport ProgressBar from 'progress';\n\nconst ROOT_DIR = path.join(__dirname, '../');\nconst totalFiles = countFiles({\n    dir: ROOT_DIR,\n});\n\nconst bar = new ProgressBar(':bar', { total: totalFiles });\n\n...\n(iterate over files, doing stuff)\nbar.tick();\n...\n```\n\n## License\n\n[MIT](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fryanhefner%2Ffile-counter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fryanhefner%2Ffile-counter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fryanhefner%2Ffile-counter/lists"}