{"id":26077494,"url":"https://github.com/w3labkr/py-fileinfo","last_synced_at":"2026-06-08T14:32:39.548Z","repository":{"id":129991694,"uuid":"488936198","full_name":"w3labkr/py-fileinfo","owner":"w3labkr","description":"Scan folders, filter files, and save paths and sizes to a text file.","archived":false,"fork":false,"pushed_at":"2025-04-29T14:49:05.000Z","size":14,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-12-10T06:27:27.552Z","etag":null,"topics":["fileinfo","filesize","py","python"],"latest_commit_sha":null,"homepage":"","language":"Python","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/w3labkr.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2022-05-05T10:58:51.000Z","updated_at":"2025-04-29T14:49:08.000Z","dependencies_parsed_at":"2023-07-05T12:16:34.908Z","dependency_job_id":null,"html_url":"https://github.com/w3labkr/py-fileinfo","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/w3labkr/py-fileinfo","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/w3labkr%2Fpy-fileinfo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/w3labkr%2Fpy-fileinfo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/w3labkr%2Fpy-fileinfo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/w3labkr%2Fpy-fileinfo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/w3labkr","download_url":"https://codeload.github.com/w3labkr/py-fileinfo/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/w3labkr%2Fpy-fileinfo/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34067348,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-08T02:00:07.615Z","response_time":111,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["fileinfo","filesize","py","python"],"created_at":"2025-03-09T03:04:45.665Z","updated_at":"2026-06-08T14:32:39.528Z","avatar_url":"https://github.com/w3labkr.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# FileInfo\n\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n![Version](https://img.shields.io/badge/version-1.4.1-blue)\n\nA Python script to recursively scan a directory, gather file information (relative path and size), filter out unwanted files/directories based on path patterns, and save the results to a text file. Useful for tasks like generating file manifests or analyzing disk usage patterns.\n\n**Author:** [w3labkr](https://w3labkr.github.io/)\n**Source:** [https://github.com/w3labkr/py-fileinfo](https://github.com/w3labkr/py-fileinfo)\n\n## Features\n\n* **Recursive Scanning:** Traverses through all subdirectories of a target directory.\n* **File Information:** Collects relative file paths and calculates file sizes.\n* **Flexible Size Units:** Formats file sizes into Bytes, KB, MB, GB, or TB.\n* **Path-Based Filtering:** Excludes files or directories if their **full absolute path** contains specified substring patterns.\n* **Command-Line Interface:** Easily configurable through command-line arguments.\n* **Text File Output:** Saves the filtered list of files and their sizes to a specified text file.\n* **Quiet Mode:** Option to suppress informational messages during execution.\n* **Error Handling:** Reports warnings (stderr) for non-critical file access issues (e.g., permission denied, file not found) and continues scanning. Exits on critical errors (e.g., target directory not found, output file write failure).\n* **Symbolic Link Handling:** By default, follows symbolic links during directory traversal (`os.walk` default). Be cautious with recursive links. If needed, modify the script to use `followlinks=False` in the `os.walk` call.\n\n## Requirements\n\n* Python 3.x. Ensure Python 3 is installed and accessible from your command line (e.g., check `python3 --version`).\n\n## Installation\n\n1.  Clone the repository or download the `fileinfo.py` script.\n    ```bash\n    # If using Git\n    git clone [https://github.com/w3labkr/py-fileinfo.git](https://github.com/w3labkr/py-fileinfo.git)\n    cd py-fileinfo\n    ```\n    Alternatively, just save the script code as `fileinfo.py`.\n2.  No external package installation is required.\n\n## Usage\n\nRun the script from your terminal using `python3`.\n\n**Note:** By default, the script scans the current directory (`.`). Use the `-d` option to specify a different directory.\n\n### Basic Syntax\n\n```bash\npython3 fileinfo.py [options]\n```\n\n### Options\n\n| Argument            | Default                                                              | Description                                                                                                                               |\n| :------------------ | :------------------------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------- |\n| `-h`, `--help`      |                                                                      | Show the help message and exit.                                                                                                           |\n| `-d`, `--directory` | `.`                                                                  | The target directory to scan recursively. **Must exist.** |\n| `-u`, `--unit`      | `MB`                                                                 | The unit for displaying file sizes. Choices: `Byte`, `KB`, `MB`, `GB`, `TB`.                                                              |\n| `-o`, `--output`    | `output.txt`                                                         | The name of the output file. This file is created **inside** the target directory (`-d`).                                                   |\n| `-e`, `--exclude`   | `['/.git/', '/node_modules/', '/__pycache__/', '.DS_Store', 'Thumbs.db']` | Substring pattern to exclude. **Checks the full path**. Can be specified multiple times to *add* patterns to the default list.           |\n| `-q`, `--quiet`     | `False`                                                              | Suppress informational messages (scan parameters, completion summary). Warnings and errors are still shown.                               |\n\n### Examples\n\n1.  **Run with defaults (scan current directory):**\n    ```bash\n    python3 fileinfo.py\n    ```\n    *(Output file will be `./output.txt`)*\n\n2.  **Scan a specific directory, use KB, and set a custom output file name:**\n    ```bash\n    python3 fileinfo.py -d /path/to/your/data -u KB -o file_list_kb.txt\n    ```\n    *(Output file will be `/path/to/your/data/file_list_kb.txt`)*\n\n3.  **Scan the current directory (`.`) and add `.log` and `/temp/` to the exclusion list:**\n    ```bash\n    python3 fileinfo.py -d . -e .log -e /temp/\n    ```\n    *(This will exclude defaults AND paths containing `.log` or `/temp/`)*\n\n4.  **Run a quiet scan using GB units:**\n    ```bash\n    python3 fileinfo.py -d /mnt/storage -u GB -q\n    ```\n\n## Output Format\n\nThe script generates a text file (specified by `-o`, default `fileinfo.txt`) inside the target directory (`-d`). Each line in this file represents a file that was **not** excluded and follows the format:\n\n```\n/relative/path/to/file, Formatted Size Unit\n```\n\n**Example (`fileinfo.txt` content):**\n\n```\n/documents/report_final.docx, 1.52 MB\n/media/videos/holiday_compilation.mp4, 780.21 MB\n/archive.zip, 1024.00 MB\n/code/main_script.py, 0.05 MB\n```\n\n* The path starts with `/` and represents the path relative to the scanned directory (`-d`).\n* Path separators are always `/`, regardless of the operating system.\n* The size is formatted to two decimal places with the chosen unit (`-u`).\n\n## Exclusion Behavior\n\n* The `-e` or `--exclude` patterns are checked against the **full absolute path** of each file encountered during the scan.\n* **Important:** Exclusion is based on a simple **substring match**. If any specified pattern exists *anywhere* within the full path string of a file, that file will be excluded.\n    * Example: If `.tmp` is an exclusion pattern:\n        * `/home/user/data/file.tmp` -\u003e Excluded.\n        * `/home/user/my.tmp.folder/data.txt` -\u003e Excluded (because `.tmp` is in the path).\n        * `/home/user/temporary/file.txt` -\u003e **Not** excluded by `.tmp` (unless another pattern matches).\n    * Example: If `/.git/` is excluded, any file whose full path contains `/.git/` (like `/path/to/project/.git/config`) will be excluded.\n* Be specific with your patterns for accurate filtering (e.g., use `/node_modules/` or `.git/` with slashes for directories, or precise filenames like `.DS_Store`).\n* Specifying `-e` multiple times **adds** patterns to the default list: `['/.git/', '/node_modules/', '/__pycache__/', '.DS_Store', 'Thumbs.db']`. There is currently no command-line option to *replace* the default list entirely without modifying the script's code.\n\n## License\n\nThis project is licensed under the [MIT License](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fw3labkr%2Fpy-fileinfo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fw3labkr%2Fpy-fileinfo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fw3labkr%2Fpy-fileinfo/lists"}