๐Ÿ—‚๏ธ files-sort

May 21, 2025 ยท View on GitHub

A powerful command-line tool to sort files in a directory based on criteria like file extension, size, or timestamps. Supports copying, moving, dry runs, verbose output, and automatic cleanup of empty directories.

๐Ÿ–ผ๏ธ Showcase

๐Ÿ“บ Watch the video

๐Ÿš€ Features

  • ๐Ÿ“„ Sort by Extension: Groups files by file type (e.g., .jpg, .pdf).
  • ๐Ÿ“ฆ Sort by Size: Categorizes files into size buckets (e.g., 0โ€“1KB, 1โ€“100MB, etc.).
  • ๐Ÿ•’ Sort by Time: Uses modified time (mtime) or created time (ctime) to group files by date.
  • ๐Ÿšš Move or Copy: Choose whether to move or copy files.
  • ๐Ÿ” Dry Run Support: Simulate the process before applying any changes.
  • ๐Ÿ’ฌ Interactive Prompts: Ask before overwriting or skipping conflicting files.
  • ๐Ÿ“ Recursive Support: Process subdirectories.

โœ… Requirements

Install dependencies:

pip install -r requirements.txt

or

pip install colorama

๐Ÿ“ฆ Installation

Option 1: Pip

Install via pip (if packaged as a CLI tool):

pip install -i https://test.pypi.org/simple/ --no-deps files-sort

To upgrade:

pip install --upgrade -i https://test.pypi.org/simple/ --no-deps files-sort

Option 2: Clone the repo

Clone the repo and make it executable:

git clone https://github.com/AfzGit/Files-Sort-py.git
cd Files-Sort-py/src/files_sort/
chmod +x files-sort.py
python files-sort.py -h

๐Ÿงฉ Usage

files-sort [OPTIONS] DIRECTORY

๐Ÿ”ง Options

OptionDescription
-s, --sortSort by extension, size, mtime, or ctime. Default: extension.
-c, --copyCopy files instead of moving them.
-v, --verboseShow detailed logs during processing.
-d, --drySimulate the sorting without actually moving/copying files.
-f, --forceSkip confirmation prompts and overwrite existing files.
-r, --recursiveInclude subdirectories recursively.
-u, --uniqueList unique file extensions in the directory and exit.

๐Ÿ“‚ Examples

๐Ÿ”ค Sort files by extension

files-sort ~/Downloads

๐Ÿ“ Sort by size (dry run + verbose)

files-sort -s size -d -v ~/Documents

๐Ÿ•“ Sort by modified time (recursively)

files-sort -s mtime -r ~/Pictures

๐Ÿ“ Copy instead of move, force overwrite

files-sort -s extension -c -f ~/Videos

๐Ÿ” See unique file extensions

files-sort -u ~/Downloads

๐Ÿงผ Auto Cleanup

If --recursive is used, the tool will also:

  • Detect and optionally remove empty directories after sorting.

๐Ÿ“Š Output Summary

At the end of execution, you'll see:

  • Total files found
  • Number of files moved or copied
  • Number of files skipped
  • Final categorization by folder