tree-to-excel 1.0.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Usdmal
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,486 @@
1
+ Metadata-Version: 2.4
2
+ Name: tree-to-excel
3
+ Version: 1.0.2
4
+ Summary: Convert Windows tree command output to Excel with structured formatting
5
+ Author-email: Usdmal <ggg.qqq.1911@gmail.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/Usdmal-tech/tree-to-excel
8
+ Project-URL: Repository, https://github.com/Usdmal-tech/tree-to-excel
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Programming Language :: Python :: 3.8
11
+ Classifier: Programming Language :: Python :: 3.9
12
+ Classifier: Programming Language :: Python :: 3.10
13
+ Classifier: Programming Language :: Python :: 3.11
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Programming Language :: Python :: 3.13
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Operating System :: Microsoft :: Windows
18
+ Classifier: Topic :: System :: Filesystems
19
+ Classifier: Topic :: Office/Business
20
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
21
+ Classifier: Topic :: Utilities
22
+ Classifier: Intended Audience :: Developers
23
+ Classifier: Intended Audience :: System Administrators
24
+ Classifier: Development Status :: 4 - Beta
25
+ Requires-Python: >=3.8
26
+ Description-Content-Type: text/markdown
27
+ License-File: LICENSE
28
+ Requires-Dist: openpyxl>=3.1.0
29
+ Requires-Dist: chardet>=5.2.0
30
+ Provides-Extra: dev
31
+ Requires-Dist: pytest>=9.1.1; extra == "dev"
32
+ Dynamic: license-file
33
+
34
+ <a id="readme-top"></a>
35
+
36
+ # Tree to Excel Parser
37
+
38
+ **Brief description:**
39
+
40
+ Converts the text output of the `tree` command (standard or with the `/A` switch) into a structured Excel spreadsheet, automatically detecting the input file encoding and [correctly](#6-parsing-features-and-limitations) identifying folders and files even for complex cases (empty folders, files without extensions, folders with a dot in the name).
41
+
42
+ The program supports three display modes – flat (`flat`), merged (`merged`), and full merged (`merged_full`) – with color-coded levels and bold font for folders.
43
+
44
+ Useful for visualizing directory hierarchies, preserving and/or auditing file structures, documenting projects, preparing nesting reports, and for subsequent analysis in Excel without manual copying and formatting.
45
+
46
+ > **IMPORTANT:** The program was primarily written for Cyrillic scripts, so it accurately detects Cyrillic fonts in UTF-8 and CP866 encodings. For other encodings, the result is not guaranteed.
47
+
48
+ <details>
49
+ <summary>Table of Contents</summary>
50
+ <ol>
51
+ <li>
52
+ <a href="#1-features">Features</a>
53
+ </li>
54
+ <li>
55
+ <a href="#2-installation">Installation</a>
56
+ <ul>
57
+ <li><a href="#requirements">Requirements</a></li>
58
+ <li><a href="#steps">Steps</a></li>
59
+ </ul>
60
+ </li>
61
+ <li>
62
+ <a href="#3-usage">Usage</a>
63
+ <ul>
64
+ <li><a href="#syntax">Syntax</a></li>
65
+ <li><a href="#options">Options</a></li>
66
+ <li><a href="#examples">Examples</a></li>
67
+ <li><a href="#notes">Notes</a></li>
68
+ </ul>
69
+ </li>
70
+ <li>
71
+ <a href="#4-output-modes">Output modes</a>
72
+ <ul>
73
+ <li><a href="#41-flat-mode">`flat` mode</a></li>
74
+ <li><a href="#42-merged-mode">`merged` mode</a></li>
75
+ <li><a href="#43-merged_full-mode">`merged_full` mode</a></li>
76
+ </ul>
77
+ </li>
78
+ <li>
79
+ <a href="#5-example-output">Example output</a>
80
+ <ul>
81
+ <li><a href="#51-input-without-a">Input (without `/A`)</a></li>
82
+ <li><a href="#52-input-with-a">Input (with `/A`)</a></li>
83
+ </ul>
84
+ </li>
85
+ <li>
86
+ <a href="#6-parsing-features-and-limitations">Parsing features and limitations</a>
87
+ <ul>
88
+ <li><a href="#61-standard-tree-format-without-a">Standard `tree` format (without `/A`)</a></li>
89
+ <li><a href="#62-tree-a-ascii-format">`tree /A` (ASCII) format</a></li>
90
+ <li><a href="#63-workarounds">Workarounds</a></li>
91
+ <li><a href="#64-encodings">Encodings</a></li>
92
+ <li><a href="#65-general-note">General note</a></li>
93
+ </ul>
94
+ </li>
95
+ <li>
96
+ <a href="#7-testing">Testing</a>
97
+ <ul>
98
+ <li><a href="#running-tests">Running tests</a></li>
99
+ </ul>
100
+ </li>
101
+ <li><a href="#8-license">License</a></li>
102
+ <li><a href="#9-contributing">Contributing</a></li>
103
+ </ol>
104
+ </details>
105
+
106
+ <!-- FEATURES -->
107
+ ## 1. Features
108
+
109
+ - **Support for two `tree` formats**
110
+ Works with both the standard `tree` output (using `├───`, `└───`) and the ASCII format (`tree /A`), which uses `+---`, `\---`.
111
+
112
+ - **Three data presentation modes**
113
+ - `flat` – folders only, each on a separate row;
114
+ - `merged` – folders only, with merged cells for repeated ancestor names (useful for visualizing hierarchy);
115
+ - `merged_full` – all items (folders and files), with cell merging.
116
+
117
+ Nesting levels are placed in corresponding columns. Folders are highlighted in **bold**.
118
+
119
+ - **Automatic encoding detection**
120
+ The input file is analysed using the `chardet` library. If the detection confidence is below 0.85, the program falls back to **UTF-8** and displays a warning, recommending that you explicitly specify the encoding via the `--encoding` parameter if needed. This ensures that even with uncertain detection, data is not lost, and the user can easily correct the situation.
121
+
122
+ - **color-coded levels**
123
+ Each nesting level gets its own background color in Excel. The path to the item is highlighted in yellow.
124
+
125
+ - **Statistics at the end of the table**
126
+ A summary row is automatically added with the total number of folders and files.
127
+
128
+ - **Flexible output**
129
+ If no output file is specified, a name is generated automatically based on the input file name and the selected mode.
130
+
131
+ - **Simplicity**
132
+ The tool is designed to be used from the command line and does not require a graphical interface.
133
+
134
+ <p align="right"><a href="#readme-top">back to top</a></p>
135
+
136
+ ---
137
+
138
+ <!-- INSTALLATION -->
139
+ ## 2. Installation
140
+
141
+ ### Requirements
142
+
143
+ - Python version **3.8** or higher.
144
+ - Installed `pip` package manager.
145
+
146
+ ### Steps
147
+
148
+ 1. Clone the repository or download the project files.
149
+ 2. Navigate to the project root directory (where `requirements.txt` is located).
150
+ 3. Install the required dependencies:
151
+
152
+ ```bash
153
+ pip install -r requirements.txt
154
+ ```
155
+
156
+ 4. To run tests, you will also need `pytest` – it is already included in `requirements.txt`, but if you do not plan to test, you can skip installing it (it is not used by the main script).
157
+
158
+ After the dependencies are installed, the `tree_to_excel.py` script is ready to use.
159
+
160
+ <p align="right"><a href="#readme-top">back to top</a></p>
161
+
162
+ ---
163
+
164
+ <!-- USAGE -->
165
+ ## 3. Usage
166
+
167
+ ### Syntax
168
+
169
+ ```bash
170
+ python src/tree_to_excel/tree_to_excel.py -i <input_file> [-m <mode>] [-o <output_file>] [-e <encoding>]
171
+ ```
172
+
173
+ ### Options
174
+
175
+ | Option | Description |
176
+ |------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------|
177
+ | `-i, --input` | **Required.** Path to the text file containing the `tree` command output. |
178
+ | `-m, --mode` | Table generation mode. Allowed values: `flat`, `merged`, `merged_full`. Default: `flat`. |
179
+ | `-o, --output` | Path to save the Excel file. If not specified, a name is generated automatically: `<input_filename>_<mode>.xlsx` in the same folder as the input file. |
180
+ | `-e, --encoding` | Force the encoding of the input file (e.g., UTF-8, cp1251). Overrides automatic detection. Useful when auto-detection fails (e.g., for rare encodings). |
181
+ | `--version` | Show the program version and exit. |
182
+
183
+ ### Examples
184
+
185
+ 1. **Basic run** (mode `flat`, output file generated automatically):
186
+
187
+ ```bash
188
+ python src/tree_to_excel/tree_to_excel.py -i tree_output.txt
189
+ ```
190
+
191
+ 2. **Specifying mode and output file**:
192
+
193
+ ```bash
194
+ python src/tree_to_excel/tree_to_excel.py -i tree.txt -m merged_full -o result.xlsx
195
+ ```
196
+
197
+ 3. **Specifying encoding**:
198
+
199
+ ```bash
200
+ python src/tree_to_excel/tree_to_excel.py -i tree.txt -m merged_full -e CP866
201
+ ```
202
+
203
+ 4. **Getting help**:
204
+
205
+ ```bash
206
+ python src/tree_to_excel/tree_to_excel.py -h
207
+ ```
208
+
209
+ ### Notes
210
+
211
+ - The input file must contain the output of the `tree` command in one of the supported formats (standard or with the `/A` switch). Examples of such files can be found in the `examples/` folder.
212
+ - If the input file does not contain a valid root path (in the format `X:\...`), the program will exit with an error.
213
+ - On successful execution, the path to the created Excel file is printed to the console.
214
+ - In case of errors (missing file, parsing issues), messages are printed to `stderr`.
215
+
216
+ <p align="right"><a href="#readme-top">back to top</a></p>
217
+
218
+ ---
219
+
220
+ <!-- OUTPUT MODES -->
221
+ ## 4. Output modes
222
+
223
+ The program supports three modes that determine which items appear in the Excel sheet and how they are grouped. Your choice depends on your needs: whether you want to see only folders or all items, and whether you need visual hierarchy with merged cells.
224
+
225
+ ### 4.1. `flat` mode
226
+
227
+ - **What goes into the table:** folders only (files are excluded).
228
+ - **How it looks:** each item (folder) occupies a separate row. The folder name is placed in the column corresponding to its nesting level (L1, L2, …). Thus, the level is visible by the column position.
229
+ - **Peculiarities:** cells are not merged; the structure is read across columns. This is convenient for further filtering or sorting in Excel.
230
+
231
+ **Example command:**
232
+
233
+ ```bash
234
+ python src/tree_to_excel/tree_to_excel.py tree.txt -m flat
235
+ ```
236
+
237
+ ### 4.2. `merged` mode
238
+
239
+ - **What goes into the table:** folders only.
240
+ - **How it looks:** for each level, columns are filled with ancestor folder names. If an ancestor name repeats for several child items, the cells with that name are merged vertically. This creates a visual tree, similar to the folder view in a file explorer.
241
+ - **Peculiarities:** merging is performed only for folders; files are ignored. The result is a compact representation of the hierarchy.
242
+
243
+ **Example command:**
244
+
245
+ ```bash
246
+ python src/tree_to_excel/tree_to_excel.py -i tree.txt -m merged
247
+ ```
248
+
249
+ ### 4.3. `merged_full` mode
250
+
251
+ - All items – both folders and files – are included in the table.
252
+ - Visually, the result is similar to the `merged` mode, but now files are also included in the rows. Folders are highlighted in **bold**, files in regular font. This makes it easy to distinguish directories from files at a glance.
253
+ - Cell merging works for all repeated ancestor names.
254
+
255
+ **Example command:**
256
+
257
+ ```bash
258
+ python src/tree_to_excel/tree_to_excel.py -i tree.txt -m merged_full
259
+ ```
260
+
261
+ <br>
262
+
263
+ | Mode | Folders | Files | Cell merging |
264
+ |:-------------:|:------------------:|:------------------:|:------------------:|
265
+ | `flat` | :white_check_mark: | :x: | :x: |
266
+ | `merged` | :white_check_mark: | :x: | :white_check_mark: |
267
+ | `merged_full` | :white_check_mark: | :white_check_mark: | :white_check_mark: |
268
+
269
+ <p align="right"><a href="#readme-top">back to top</a></p>
270
+
271
+ ---
272
+
273
+ <!-- EXAMPLE OUTPUT -->
274
+ ## 5. Example output
275
+
276
+ ### 5.1. Input (without `/A`)
277
+
278
+ Example text file `project_tree.txt` with the following content (output of the `tree` command without the `/A` switch):
279
+
280
+ ```text
281
+ Folder PATH listing for volume System
282
+ Volume serial number is 00000001 1234:5678
283
+ C:\MY_PROJECT
284
+ ├───src
285
+ │ ├───core
286
+ │ │ ├───utils
287
+ │ │ │ └───helpers.py
288
+ │ │ └───main.py
289
+ │ └───tests
290
+ │ └───test_core.py
291
+ ├───docs
292
+ │ ├───readme.md
293
+ │ └───guide.pdf
294
+ └───scripts
295
+ └───deploy.bat
296
+ ```
297
+
298
+ After execution, the file `project_tree_[mode].xlsx` is created:
299
+
300
+ - Example output in `flat` mode:
301
+
302
+ <div align="center">
303
+
304
+ ![flat mode](examples/project_tree_flat.jpg)
305
+
306
+ </div>
307
+
308
+ - Example output in `merged` mode:
309
+
310
+ <div align="center">
311
+
312
+ ![merged mode](examples/project_tree_merged.jpg)
313
+
314
+ </div>
315
+
316
+ - Example output in `merged_full` mode:
317
+
318
+ <div align="center">
319
+
320
+ ![merged_full mode](examples/project_tree_merged_full.jpg)
321
+
322
+ </div>
323
+
324
+ ### 5.2. Input (with `/A`)
325
+
326
+ Example text file `project_tree.txt` with the following content (output of the `tree` command with the `/A` switch):
327
+
328
+ ```text
329
+ Folder PATH listing for volume System
330
+ Volume serial number is 00000001 1234:5678
331
+ C:\MY_PROJECT
332
+ +---src
333
+ │ +---core
334
+ │ │ +---utils
335
+ │ │ │ \---helpers.py
336
+ │ │ \---main.py
337
+ │ \---tests
338
+ │ \---test_core.py
339
+ +---docs
340
+ │ +---readme.md
341
+ │ \---guide.pdf
342
+ \---scripts
343
+ \---deploy.bat
344
+ ```
345
+
346
+ After execution, the file `project_tree_[mode].xlsx` is created:
347
+
348
+ - Example output in `flat` mode:
349
+
350
+ <div align="center">
351
+
352
+ ![flat mode](examples/project_tree_a_flat.jpg)
353
+
354
+ </div>
355
+
356
+ - Example output in `merged` mode:
357
+
358
+ <div align="center">
359
+
360
+ ![merged mode](examples/project_tree_a_merged.jpg)
361
+
362
+ </div>
363
+
364
+ - Example output in `merged_full` mode:
365
+
366
+ <div align="center">
367
+
368
+ ![merged_full mode](examples/project_tree_a_merged_full.jpg)
369
+
370
+ </div>
371
+
372
+ <p align="right"><a href="#readme-top">back to top</a></p>
373
+
374
+ ---
375
+
376
+ <!-- PARSING FEATURES AND LIMITATIONS -->
377
+ ## 6. Parsing features and limitations
378
+
379
+ When converting the tree to Excel, it is important to be aware of the parser's behavior and its limitations, especially regarding how it distinguishes folders from files.
380
+
381
+ ### 6.1. Standard `tree` format (without `/A`)
382
+
383
+ The parser determines the item type (folder or file) as follows:
384
+
385
+ 1. **If the item has children** – it is a **folder**.
386
+ 2. **If the item has no children, but has a marker** (`+---`, `\---`, `├───`, `└───`):
387
+ - **and the name contains a dot (`.`)**: the item is treated as a **file**.
388
+ - **and the name does not contain a dot**: the item is treated as an **empty folder**.
389
+
390
+ This logic may fail in the following cases:
391
+
392
+ - **Folders with a dot in the name**
393
+ For example, `project.v1`, `.config`, `my.folder`.
394
+ Because the name contains a dot, the parser will consider them files, even if they are empty folders (or folders with no visible children in the `tree` output).
395
+ *Result:* such folders will not appear in `flat` and `merged` modes (which only output folders) and will be displayed as files in `merged_full`.
396
+
397
+ - **Files without an extension**
398
+ For example, `README`, `Makefile`, `LICENSE`, `Dockerfile`.
399
+ *Result:* they will be incorrectly included in folder lists in `flat` and `merged` modes, and in `merged_full` they will be highlighted in bold as folders.
400
+
401
+ ### 6.2. `tree /A` (ASCII) format
402
+
403
+ In this format, all markers use only the characters `+`, `\`, `|`, and spaces. The parser **does not use markers** to determine the item type – only items that have children are considered folders.
404
+
405
+ **Empty folders are not recognized** and are always identified as files. The `tree /A` command on Windows does not output empty folders with branch markers as clearly as the standard output, or it outputs them without continuation indicators, making it impossible for the parser to distinguish them from extension-less files.
406
+
407
+ ### 6.3. Workarounds
408
+
409
+ If your structure contains **folders with dots** or **files without extensions**, and you want to avoid misclassification, use one of the following methods:
410
+
411
+ - Use the `tree /A` (ASCII) output for such structures – then folders with dots will be correctly identified (provided they have children). However, **empty folders** will then be incorrectly classified as files (and consequently will not appear in `flat` and `merged` modes).
412
+ - Keep the standard `tree` output and **manually check** the resulting Excel file, adjusting item types if necessary (this can be done in the spreadsheet if you know which items should be folders).
413
+
414
+ ### 6.4. Encodings
415
+
416
+ The program automatically detects the input file encoding using the `chardet` library.
417
+ The confidence threshold is set to **0.85** – if the detector does not reach this confidence, it falls back to `UTF-8` as a default, and a warning is printed to the console recommending that you specify the encoding manually if the names appear incorrect.
418
+
419
+ For most common encodings (UTF-8, WINDOWS-1251, ISO-8859-1), auto-detection works reliably. For less common ones (CP866, EUC-KR, GB2312, SHIFT-JIS, etc.), errors are possible.
420
+
421
+ **If you encounter garbled characters in Excel**, run the program again with the `--encoding` parameter, specifying the correct encoding.
422
+
423
+ Example:
424
+
425
+ ```bash
426
+ python src/tree_to_excel/tree_to_excel.py -i my_tree.txt --encoding CP866
427
+ ```
428
+
429
+ ### 6.5. General note
430
+
431
+ The tool is designed for **quick analysis and visualization** of folder structures, not for absolutely accurate reconstruction of the file system.
432
+
433
+ <p align="right"><a href="#readme-top">back to top</a></p>
434
+
435
+ ---
436
+
437
+ <!-- TESTING -->
438
+ ## 7. Testing
439
+
440
+ The project includes a test suite to verify the correctness of parsing and the behavior of various modes. The tests cover:
441
+
442
+ - standard `tree` format and `/A` format;
443
+ - handling of files encoded in UTF-8, CP866, CP1251, EUC-KR, GB2312, ISO-8859-1, SHIFT_JIS, WINDOWS-1251, WINDOWS-1252 (you can also test with any other encoding yourself);
444
+ - edge cases (folders with dots, files without extensions, empty folders);
445
+ - all saving modes (`flat`, `merged`, `merged_full`);
446
+ - handling of erroneous input (missing root path, empty file).
447
+
448
+ ### Running tests
449
+
450
+ 1. Install development dependencies (if you haven't already):
451
+
452
+ ```bash
453
+ pip install -r requirements.txt
454
+ ```
455
+
456
+ 2. Run the following command from the project root:
457
+
458
+ ```bash
459
+ pytest -v
460
+ ```
461
+
462
+ 3. For a more detailed report, use:
463
+
464
+ ```bash
465
+ pytest -v --tb=short
466
+ ```
467
+
468
+ <p align="right"><a href="#readme-top">back to top</a></p>
469
+
470
+ ---
471
+
472
+ <!-- LICENSE -->
473
+ ## 8. License
474
+
475
+ This project is distributed under the **MIT** license. The full license text is available in the [`LICENSE`](LICENSE) file in the root of the repository.
476
+
477
+ <p align="right"><a href="#readme-top">back to top</a></p>
478
+
479
+ ---
480
+
481
+ <!-- CONTRIBUTING -->
482
+ ## 9. Contributing
483
+
484
+ If you find a bug or would like to suggest an improvement, please contact me at [usdmal@rambler.ru](mailto:usdmal@rambler.ru) or create an [Issue](https://github.com/Usdmal-tech/tree_to-excel/issues) with a detailed description.
485
+
486
+ <p align="right"><a href="#readme-top">back to top</a></p>