Use files-flattener to flatten your whole structured code project into a single file.
Project description
Files Flattener
This repository contains implementations for recursively reading all files in a specified directory and outputting their filenames and contents to a specified output file.
Why do I need this?
Imagine you are working on a project and need to share the project structure and file contents with a collaborator or an AI platform for analysis. Instead of manually copying and pasting each file's content, you can use the files_flattener.py script to generate a single file with all the necessary information. This consolidated file can then be easily shared, ensuring that the recipient has all the context needed to understand the project.
Example
Assume you have the following directory structure:
|
|--folder1
| |--file1.txt
| |--file2.txt
|--file3.txt
And you have an .ignore file in the root directory with the following content:
folder1/file2.txt
# Exclude itself
.ignore
Running the implementation will process the files, ignoring folder1/file2.txt and .ignore itself as specified in the .ignore file. The output file will contain the contents of the remaining files in the following format:
**folder1/file1.txt:**
[...file1.txt's content...]
**file3.txt:**
[...file3.txt's content...]
Getting Started
Usage
-
Ensure you have Python installed on your system.
-
Install the package using pip:
pip install files_flattener
-
Run the command:
flt <directory> <output_file> [<ignore_file>]
<directory>: The path of the directory containing the files to be flattened.<output_file>: The path of the output file where the contents of the files will be written.[<ignore_file>]: (Optional) The path to a file containing patterns of files to ignore. If not provided, the script will look for a '.ignore' file in the specified directory. If the '.ignore' file is not found, no files will be ignored.
Development
Install the required dependencies
pip install -r requirements.txt
Run the script locally
python -m files_flattener.cli <directory> <output_file> [<ignore_file>]
Build the package
Ensure wheel is installed:
pip install wheel
Generate the distribution files:
. scripts/build.sh
Publish the package to PyPI
Install twine if you haven't already:
pip install twine
Upload the distribution files to PyPI:
. scripts/upload.sh
TODO
- Add dry-run mode to preview the output before writing to the file.
- Make a web app based on Vue3.
- Use
.ignoreto exclude or include files for flattening.
License
This project is licensed under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file files_flattener-0.1.2.tar.gz.
File metadata
- Download URL: files_flattener-0.1.2.tar.gz
- Upload date:
- Size: 5.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e08becbd043dec79719f78b38e9296131a091b7bc943766808eb221f30c4bbd7
|
|
| MD5 |
572f2a1718dc6c016638ace76cb7bc3e
|
|
| BLAKE2b-256 |
5eee6c0eeaf53fe359837a5f2102d5b121850d71b4d63162bdd57bae58f89f66
|
File details
Details for the file files_flattener-0.1.2-py3-none-any.whl.
File metadata
- Download URL: files_flattener-0.1.2-py3-none-any.whl
- Upload date:
- Size: 6.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
37076702c37c09ad7d10d47769870495ae102128cc235699dfa792bcd113f763
|
|
| MD5 |
b3f26b1bd55faa071e57901f10673a0c
|
|
| BLAKE2b-256 |
13cf4ccdc8783527ff83eb10e4aa754c5adebb94789f150accde14f781448210
|