A simple command-line tool to archive a project's directory structure and source code into a single, well-organized Markdown file.
This tool creates a backup in two parts: first, it displays a clean tree of the folder structure, and second, it lists the contents of each file, making it easy to review and share your code.
- Two-Part Format: Generates a clean folder structure tree and a separate section for file contents.
- Portable Archive: Saves the entire project's text-based source code in one Markdown file.
- Smart Exclusions: Easily ignore files and directories you don't need (like
node_modules
or__pycache__
). - Binary File Handling: Detects and skips the content of binary files (e.g., images, executables), noting their presence in the file tree.
- Simple CLI: A straightforward command-line interface for easy use.
- Python 3.x
- No external libraries needed.
- Save the Script: Save the Python code as
backup_tool.py
. - Open a Terminal: Navigate to the directory where you saved the script.
- Run the Command: Execute the script with the following structure.
python backup_tool.py <source_directory> <output_markdown_file> [options]
source_directory
: The path to the project you want to back up.output_markdown_file
: The name of the Markdown file to create (e.g.,project_backup.md
).
-e, --exclude [PATTERN_1] [PATTERN_2] ...
: (Optional) A space-separated list of file or directory patterns to exclude.
To back up a project in the my-app
folder to a file named my-app-backup.md
:
python backup_tool.py ./my-app my-app-backup.md
To back up a project while ignoring the dist
folder, all .log
files, and any .env
files:
python backup_tool.py ./my-project backup.md --exclude "dist" "*.log" ".env"
The generated Markdown file is structured for maximum clarity:
-
Folder Structure: A visual tree representing the hierarchy of your directories and files.
## Folder Structure my-project/ - index.html - assets/ - style.css - logo.png - js/ - app.js
-
File Contents: Each file's content is then listed, preceded by a clear header. Binary files are noted and their content is skipped.
-- index.html -- ```html <!DOCTYPE html> <html> ... </html>
-- assets/style.css --
body { ... }
-- assets/logo.png -- [Binary file, content not included]