Skip to main content

A module for sorting files into folders based on their extensions

Project description

Extensort

Extensort is a Python module that simplifies the process of organizing files by sorting them into folders based on their extensions. It provides an efficient way to clean up cluttered directories and maintain a well-organized file system.

Features

  • Automatically sort files into folders based on their extensions
  • Customizable mapping of file extensions to folder names
  • Find all unique file extensions in a directory
  • Detailed sorting summary including moved, skipped, and error counts
  • Color-coded console output for better visibility of the sorting process

Installation

You can install Extensort using pip:

pip install extensort

Usage

Here's a quick example of how to use Extensort:

from extensort import sort_files, find_extensions

# Define the directory to sort
directory_to_sort = "/path/to/your/directory"

# Find all extensions in the directory
all_extensions = find_extensions(directory_to_sort)
print(f"Found extensions: {all_extensions}")

# Define how you want to sort the files
extension_mapping = {
    ".txt": "Text Files",
    ".pdf": "Documents",
    ".jpg": "Images",
    ".png": "Images",
    ".py": "Python Scripts"
}

# Sort the files
summary = sort_files(directory_to_sort, extension_mapping)

print("Sorting complete!")
print(f"Moved: {summary['moved']}")
print(f"Skipped: {summary['skipped']}")
print(f"Errors: {summary['errors']}")

Detailed Usage

Finding Extensions

The find_extensions function scans a directory and returns a set of all unique file extensions:

extensions = find_extensions("/path/to/directory")

Sorting Files

The sort_files function organizes files into folders based on their extensions:

extension_mapping = {
    ".txt": "Text",
    ".jpg": "Images",
    ".png": "Images",
    ".docx": "Documents",
    ".pdf": "Documents",
    ".py": "Code",
    ".js": "Code"
}

summary = sort_files("/path/to/sort", extension_mapping)

The function returns a summary dictionary with the following keys:

  • moved: Number of files successfully moved
  • skipped: Number of files skipped (no matching extension in the mapping)
  • errors: Number of errors encountered during the sorting process

Contributing

Contributions to Extensort are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

extensort-0.1.0.tar.gz (2.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

extensort-0.1.0-py3-none-any.whl (3.4 kB view details)

Uploaded Python 3

File details

Details for the file extensort-0.1.0.tar.gz.

File metadata

  • Download URL: extensort-0.1.0.tar.gz
  • Upload date:
  • Size: 2.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.2

File hashes

Hashes for extensort-0.1.0.tar.gz
Algorithm Hash digest
SHA256 30e7c67630b137ff8c8a9d086693b75ac5c48e5351160d91cd84c60735f99dbd
MD5 c4b4a8e270314dbb0d529efa90b25c1d
BLAKE2b-256 a8bfdab2e61ab10f0d7e830aa2a045452915881e0c089843980134d4ed12a513

See more details on using hashes here.

File details

Details for the file extensort-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: extensort-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.2

File hashes

Hashes for extensort-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f837e77f5ad84c6da1cbcc967863c748ffb60ad788fecf9d7264a9c33bebca68
MD5 d46c04395af02fba2510000d8e6f3667
BLAKE2b-256 f8646ba23989a0b1dce282a0a30e38c429f7a15a460ac7212b2925df532cfea2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page