Python · File Utility
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.
Pythonos / pathlibCSV
Abstract
The 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.
The solution
A configurable "edit-and-run" script that scans a directory, filters it, and writes a formatted text or CSV manifest with extension statistics.
The result
Zero-effort file manifests ready for documentation, client reports or database imports.
Input & Output
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 Diagram
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
| Option | Purpose |
|---|---|
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
# place the script next to your filespython file_lister_v2.pySource Code
import os
import datetime
from collections import defaultdict
# --- CONFIGURATION FLAGS ---
# Set these flags to control the script's behavior.
# Sort files by 'name' (alphabetically) or 'created' (creation time).
SORT_BY = 'name'
# Choose output format: 'default' for a numbered list, 'csv' for plain CSV format.
OUTPUT_FORMAT = 'default'
# Omit the script's own file (.py) from the output.
# Set to 'False' to include the script file.
OMIT_PY_FILES = True
# Omit all text files (.txt) from the output.
# Set to 'False' to include text files.
OMIT_TXT_FILES = True
# Omit the file size from the output.
# Set to 'True' to remove the size information.
OMIT_FILE_SIZE = True
# --------------------------------------------------------------------------
def format_size(size_in_bytes):
"""
Formats file size into a human-readable string (KB, MB, GB).
"""
if size_in_bytes < 1024:
return f"{size_in_bytes} B"
elif size_in_bytes < 1024 * 1024:
return f"{size_in_bytes / 1024:.2f} KB"
elif size_in_bytes < 1024 * 1024 * 1024:
return f"{size_in_bytes / (1024 * 1024):.2f} MB"
else:
return f"{size_in_bytes / (1024 * 1024 * 1024):.2f} GB"
def main():
"""
This script is designed to list all files in the directory it is run from,
gather detailed information about them, and save that information to a
text file named 'extracted_files_details.txt'.
The script's behavior is configured by the flags at the top of this file,
making it easy to customize without using command-line arguments.
How to use:
1. Place this script in the directory you want to catalog.
2. Edit the configuration flags above to your desired settings.
3. Open a terminal or command prompt.
4. Navigate to the directory where the script is located.
5. Run the script by typing 'python file_lister_v2.py' and pressing Enter.
6. A new file, 'extracted_files_details.txt', will be created in the same folder.
"""
root_folder = os.getcwd()
output_filename = "extracted_files_details.txt"
… 74 more lines - loading the full file
Released under the MIT license. Free to use, modify and share.
Impact & Benefits
Screenshots
Frequently Asked Questions
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.
Related
Generate a Clean Folder Tree of Any Project with Python
Generates a filtered, tree-style map of any codebase for READMEs, onboarding and AI context.
Read documentationMerge Selected Project Files into One AI-Ready Text Block
Select files from a local project and merge them into one sanitised, AI-ready text block.
Read documentation
