# List Every File in a Folder to a Text or CSV Manifest with Python

> Drop file_lister_v2.py in a folder and run it: you get extracted_files_details.txt with every file name, size and an extension count, as a readable list or CSV.

URL: https://thuyavan.netlify.app/scripts/directory-file-lister
Updated: 2026-10-07

## Problem
Listing hundreds of assets with their metadata by hand is a time sink, and OS file views do not allow copy-pasting a tidy text list.

## Solution
A configurable "edit-and-run" script that scans a directory, filters it, and writes a formatted text or CSV manifest with extension statistics.

## Result
Zero-effort file manifests ready for documentation, client reports or database imports.

## Input
- The folder containing file_lister_v2.py (scanned in place)

## Output
- extracted_files_details.txt – numbered list or CSV

## Optional output
- Extension distribution summary (e.g. png: 45, jpg: 12)
- Human-readable sizes (KB / MB / GB)

## System flow
Target folder (Assets, docs, scripts) -> Scan (Walk directory) -> Filter (Hide self · toggle types) -> Format (Default list or CSV) -> Manifest (extracted_files_details.txt)

## How it works
- **Self-exclusion:** The script hides itself so the list stays clean.
- **Format targeting:** Toggle visibility of specific file types such as .txt or .py.
- **Two report styles:** Numbered human-readable list, or CSV for Excel and databases.
- **Directory health:** Counts every extension and converts raw bytes to readable sizes.

## Configuration
- `SORT_BY`: 'name' for alphabetical, 'created' for chronological.
- `OUTPUT_FORMAT`: 'default' (list) or 'csv'.
- `OMIT_FILE_SIZE`: True for a name-only list, False to include sizes.

## How to run
Copy file_lister_v2.py into the folder to catalogue:

    # place the script next to your files
Run it:

    python file_lister_v2.py

## Impact
- Quick asset lists for project hand-offs (100+ UI/UX images).
- Table-of-contents generation for source or assets.
- Data-entry automation without manual typing.
- Space audits by sorting on size to find heavy files.

## FAQ
**How do I export a folder listing to CSV with Python?**
Set OUTPUT_FORMAT = 'csv' at the top of file_lister_v2.py and run it. The result opens directly in Excel.

**Does the script list itself?**
No. It excludes itself so the manifest only contains your files.

**Can I sort by creation date?**
Yes. Set SORT_BY to 'created' for chronological order or 'name' for alphabetical.

