Skip to content

Commit 09bf16c

Browse files
File sort
1 parent d2fff61 commit 09bf16c

File tree

17 files changed

+237
-20
lines changed

17 files changed

+237
-20
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.0.2] - Unreleased
9+
10+
### Added
11+
12+
- Option: sorting files and directories
13+
814
## [0.0.1] - 2025-09-14
915

1016
### Added

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ A lightweight Java library for printing directory structures in a clean, tree-li
77
- Limit displayed children (fixed value or dynamically)
88
- Compact directory chains
99
- Maximum depth
10+
- File sort
1011

1112
> [!CAUTION]
1213
> This lib was developed just for fun, and has not been thoroughly tested!
@@ -73,6 +74,7 @@ base/
7374
* [Children limit](#children-limit)
7475
* [Compact directories](#compact-directories)
7576
* [Max depth](#max-depth)
77+
* [Sorting](#sorting)
7678

7779
## Tree format
7880
Choose between different tree formats.
@@ -224,6 +226,31 @@ max_depth/
224226
└─ ... (max depth reached)
225227
```
226228

229+
## Sorting
230+
Files and directories can be sorted using a custom comparator (default is alphabetical order). Class `PrettyPrintOptions.Sorts` helps you by providing some basic comparators.
231+
232+
```java
233+
// Example: Sorting.java
234+
var prettyPrinter = FileTreePrettyPrinter.builder()
235+
.customizeOptions(options -> options.withFileSort(PrettyPrintOptions.Sorts.ALPHABETICAL_ORDER.reversed()))
236+
.build();
237+
```
238+
```
239+
file_sort/
240+
├─ dir_C/
241+
│ ├─ file_C_3
242+
│ ├─ file_C_2
243+
│ └─ file_C_1
244+
├─ dir_B/
245+
│ ├─ file_B_3
246+
│ ├─ file_B_2
247+
│ └─ file_B_1
248+
└─ dir_A/
249+
├─ file_A_3
250+
├─ file_A_2
251+
└─ file_A_1
252+
```
253+
227254
# Changelog
228255
See [CHANGELOG.md](CHANGELOG.md) for released versions.
229256

ROADMAP.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
- [ ] Directory children limitation function helper
1919
- [ ] More default emojis
2020
- [ ] Filtering
21-
- [ ] Ordering
21+
- [x] Ordering
2222

2323
## Other ideas
2424
- [ ] Custom tree format option
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package io.github.computerdaddyguy.jfiletreeprettyprinter.example;
2+
3+
import io.github.computerdaddyguy.jfiletreeprettyprinter.FileTreePrettyPrinter;
4+
import io.github.computerdaddyguy.jfiletreeprettyprinter.PrettyPrintOptions;
5+
6+
public class Sorting {
7+
8+
public static void main(String[] args) {
9+
var prettyPrinter = FileTreePrettyPrinter.builder()
10+
.customizeOptions(options -> options.withFileSort(PrettyPrintOptions.Sorts.ALPHABETICAL_ORDER.reversed()))
11+
.build();
12+
var tree = prettyPrinter.prettyPrint("src/example/resources/file_sort");
13+
System.out.println(tree);
14+
}
15+
16+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
small file
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
looooooongest file
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
medium file!
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
small file
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
looooooongest file
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
medium file!

0 commit comments

Comments
 (0)