# File List Sorter

Sort a pasted list of filenames or paths in natural order (img2 before img10), by extension, folder depth or size, with folders first — free and private in your browser.

## Run it

- **CLI:** `gizza tool file-list-sorter "img10.png
img2.png
src/main.rs
docs/report.docx
README.md"`
- **Web:** https://gizza.ai/tools/file-list-sorter/
- **Agents:** machine-readable descriptor (parameters JSON Schema) at https://gizza.ai/tools/file-list-sorter/tool.json

## Inputs

- `paths` — File names or paths (one per line) _(field)_
- `sort_by` — Sort by _(field)_
- `order` — Order _(field)_
- `ignore_case` — Ignore case (file-manager style) _(field)_
- `dirs_first` — Folders first _(field)_
- `group_by_dir` — Keep each folder's contents together _(field)_
- `unique` — Remove duplicate paths _(field)_
- `trim` — Ignore surrounding whitespace _(field)_
- `format` — Output shape _(field)_

## Output

- Sorted list (text)

## Query parameters

Open the tool pre-filled and auto-run via URL:

- `paths` — File names or paths (one per line)
- `sort_by` — Sort by
- `order` — Order
- `ignore_case` — Ignore case (file-manager style)
- `dirs_first` — Folders first
- `group_by_dir` — Keep each folder's contents together
- `unique` — Remove duplicate paths
- `trim` — Ignore surrounding whitespace
- `format` — Output shape

Example: `https://gizza.ai/tools/file-list-sorter/?paths=img10.png%0Aimg2.png%0Asrc%2Fmain.rs%0Adocs%2Freport.docx%0AREADME.md&sort_by=natural&order=asc&ignore_case=true&dirs_first=true&group_by_dir=true&unique=true&trim=true&format=list`

---

## About this tool

**File List Sorter** takes a pasted list of file names or paths and puts it in
the order a *file manager* would use, not the order a plain text sort gives.
A plain sort compares text character by character, so `img10.png` lands before
`img2.png` and `README.md` jumps ahead of every lowercase name. This tool
understands that a path has structure: a folder, a file name, an extension, a
depth, and sometimes a size column.

### Worked example

Paste this list:

```
img10.png
img2.png
img1.png
```

With **Sort by = Natural order**, the result is:

```
img1.png
img2.png
img10.png
```

The digit runs are compared as numbers, so `2` sorts before `10` instead of
after it. Switch **Sort by** to *Alphabetical* and you get the machine order
(`img1.png`, `img10.png`, `img2.png`) — useful when you need to match what
`sort` or a Git tree does.

### The options

- **Sort by** — *Natural* is human numbering over the whole path. *Alphabetical*
  is plain codepoint order. *File name only* ignores the folders above each
  file, so `zzz/apple.txt` sorts before `aaa/banana.txt`. *Extension* groups by
  file type (entries with no extension come first), then naturally by path.
  *Folder depth* lists the shallowest paths first. *Size* reads a size column
  off each line.
- **Order** — ascending or descending. Folders-first is *not* reversed: folders
  stay on top in both directions, the way Explorer and Finder behave.
- **Ignore case** — on by default, so `README.md` sits next to `readme.txt`.
  Turn it off for the case-sensitive order of `ls`, `sort` or a Git tree.
- **Folders first** — on by default. An entry counts as a folder when it ends in
  a slash (`src/`) *or* when another pasted entry lives underneath it (`src` is
  a folder if `src/main.rs` is also in the list).
- **Keep each folder's contents together** — sorts by parent folder first, then
  applies the chosen key inside each folder. Handy for sorting a deep `find`
  dump by file name or size while keeping each folder's files side by side.
- **Remove duplicate paths** — keeps the first spelling of each path.
  `./src/app.js`, `src/app.js` and `SRC/APP.JS` count as one entry when *Ignore
  case* is on.
- **Ignore surrounding whitespace** — on by default, because indented `tree` or
  `ls` output otherwise sorts by its indentation.
- **Output shape** — a plain list ready to paste back into a script, a numbered
  list, a table with type/extension/depth/size columns, or JSON.

### Handy for

- Ordering exported screenshots, scans, episodes or `page-1 … page-10` files so
  they concatenate in the right sequence.
- Tidying `ls -1`, `find .`, `git ls-files` or `du -h` output before pasting it
  into a script, ticket or README.
- Grouping a messy download folder by file type, or finding the deepest paths in
  a repository.
- Turning a `du -h` dump into a biggest-files-first list.

Everything runs **locally in your browser** via WebAssembly — your file list is
never uploaded, and nothing is read from your disk. Up to **20,000 paths** per
run; split a longer list and sort it in batches.

## FAQ

<details>
<summary>What exactly is "natural" sorting?</summary>

Natural sorting compares runs of digits as numbers instead of as text, so
`img2.png` comes before `img10.png` and `v1.9` before `v1.10`. The letters
around the digits are still compared as text. Leading zeros are handled too:
`file01` and `file1` compare as the same number, with the shorter spelling
first. Choose *Alphabetical* if you specifically want the raw codepoint order.

</details>

<details>
<summary>How does it know which entries are folders?</summary>

Two ways, since a pasted list carries no filesystem information. An entry that
ends in a slash (`src/`, `assets/img/`) is treated as a folder. So is any entry
that another pasted entry sits underneath — if the list contains both `src` and
`src/main.rs`, then `src` is a folder. Everything else is treated as a file. If
your listing has no trailing slashes and no parent entries, turn **Folders
first** off, since there is nothing for it to lift.

</details>

<details>
<summary>How do I sort by size?</summary>

Include a size on each line and pick **Sort by = Size**. A size is recognised
when it carries a unit — `4.0K  src/app.js`, `src/app.js  1.2MB`, `512B`,
`3GiB` — either before or after the path, which is exactly what `du -h` and
`ls -lh` produce. K/M/G/T are 1024-based. A bare byte count is only read when a
TAB separates it from the path, so a name like `2024 report.txt` keeps its year
instead of being mistaken for a size. Entries with no size always sort last, and
sorting by size with no size column anywhere is reported as an error rather than
silently ignored.

</details>

<details>
<summary>Does it handle Windows paths and mixed separators?</summary>

Yes. Both `/` and `\` count as folder separators, so `docs\report.docx` and
`docs/report.docx` are understood the same way for depth, folder and extension
purposes. A leading `./` is ignored. Your entries are printed back in exactly
the spelling you pasted — the normalisation is only used for comparing.

</details>

<details>
<summary>What counts as the extension?</summary>

The text after the last dot in the file name. So `archive.tar.gz` has the
extension `gz`, `README` has none, and dotfiles like `.gitignore` have none
either (a leading dot starts the name, it does not start an extension). Folders
never carry an extension, even if their name contains a dot.

</details>

<details>
<summary>Is there a limit, and does my list leave my device?</summary>

A run is capped at 20,000 paths; past that you get a clear error asking you to
split the list. Blank lines are skipped and do not count. The sorting itself
runs in WebAssembly inside your browser, so the list never leaves your device
and no file contents are read — only the names you paste.

</details>

## Related tools

- [Article to EPUB](https://gizza.ai/tools/article-to-epub/): Turn article text or cleaned HTML into a valid EPUB 3 ebook with metadata, chapter splits, and a real table of contents. Runs in your browser.
- [Preview a Bulk File Rename](https://gizza.ai/tools/bulk-file-renamer/): Preview old-to-new filename mappings with find/replace, regex, numbering, case conversion, prefix/suffix, and collision warnings.
- [Citation Generator](https://gizza.ai/tools/citation-generator/): Free APA 7, MLA 9, Chicago and Harvard citation generator — format author, title, year, journal and URL into a correct reference right in your browser.
- [Config Merge Tool](https://gizza.ai/tools/config-merge/): Merge layered JSON, YAML, TOML and .env configuration files with override precedence, array strategy, null deletion and variable substitution.
- [Disk Usage by File Type](https://gizza.ai/tools/disk-usage-by-filetype/): Paste du, find or ls output and get a sorted bar chart of disk usage by file extension or category, with size, share and file count — free and private in your browser.
