← All projectsTOOL / OPEN SOURCE

Python to Textfile

Your source files.
Collected as text.

Copy Python and JSON files to text while preserving their folder structure, making a collection of source files easier to organize.

05 / PYTHON
project/├ main.py
└ config.json
→
textfile/├ main.txt
└ config.txt
LUCIANLABS / PYTHON TO TEXTFILEBuilt to be used. And shared.
HOW IT WORKS

How to use it.

01

Choose a folder.

Run ptt.py and enter the folder containing the files to convert.

02

Include the subfolders.

Find Python and JSON files and copy them with a .txt extension. Original files remain in place.

03

Keep the folder structure.

Results are saved in a dated folder beside the script. Same-name .py and .json files in one folder can map to the same output file.

IN DEPTH

In depth

What the script actually does, how the output is laid out, and what to watch for, straight from the source.

What it does

ptt.py finds every .py and .json file in a folder and all its subfolders and makes copies with a .txt extension. Originals stay untouched. It uses only Python’s standard library.

It is handy when you need to share code somewhere that won’t accept .py or .json uploads, or want to skim a project’s source as plain text.

How the output is laid out

Each run creates a new folder named by date_time inside python-to-textfile/ next to the script, keeping the original folder structure. File metadata such as modification time is copied too (shutil.copy2).

project/                     python-to-textfile/2025-04-11_16-19-56/
├─ main.py          →        ├─ main.txt
└─ app/                      └─ app/
   ├─ api.py                    ├─ api.txt
   └─ config.json               └─ config.txt

When it finishes it reports how many of the files found were copied. If you don’t pass a path as an argument, it asks for one.

Things to watch for

  • If a folder has a .py and a .json with the same name (say config.py and config.json), both become config.txt and the JSON copy, made second, overwrites the first.
  • To include other extensions, edit the extensions list in the source (default ['.py', '.json']).
  • Output goes next to the script, so it is tidier to keep the script outside the project you are copying.

FAQ

What do I need to run it?

Just Python 3. Clone the repository and run python3 ptt.py or python3 ptt.py path.

Does it change or delete originals?

No. It only makes copies and never touches the originals.

GET STARTED

Try it in
your workflow.

Run with Python 3. The script will ask for the folder path.

TERMINAL
git clone https://github.com/Seokwoooo/Python-To-Textfile.git
cd Python-To-Textfile
python3 ptt.py
Read the full guide on GitHub ↗
← Explore other projects