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.1.tar.gz (3.7 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.1-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: extensort-0.1.1.tar.gz
  • Upload date:
  • Size: 3.7 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.1.tar.gz
Algorithm Hash digest
SHA256 734bf11db81d8f8f01acc2d8d1d18631d4ccd3ef701af4e67eb035ac9177fdb7
MD5 eda43c03b4913b24c69aa5a92f5597ea
BLAKE2b-256 5ab12b83eadaf20e9e03cfa95518cdf8a507c4ed27d182aa00898a15dd19d9d5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: extensort-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 4.2 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0549c4e4bb1fc88a5dd664da0c0bb90afece5d0a59eea9a3bec83126e1dd557f
MD5 47b931c6241287965626137472541532
BLAKE2b-256 abfabfe3c4c0de6d6e4ae0cb7623e9560732e5b21b1485234f7122a7ab6f8729

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