Giter VIP home page Giter VIP logo

folder_sorter_threads's Introduction

Sorting Folder

This is a Python script that sorts files in a specified folder based on their file extensions. It uses multithreading to improve performance when handling large folders.

Usage

The script can be executed with the following command-line arguments:

python sort_folder.py [-h] [--source SOURCE] [--output OUTPUT]
  • --source, -s: Specifies the source folder to be sorted. Default value is "TestFolder".
  • --output, -o: Specifies the output folder where the sorted files will be placed. Default value is "dist".

Dependencies

The script requires the following dependencies:

  • argparse: Used for parsing command-line arguments.
  • pathlib: Provides an object-oriented interface to filesystem paths.
  • shutil: Used for file copying.
  • queue: Implements a thread-safe queue.
  • threading: Provides high-level threading interfaces.
  • logging: Used for logging messages during the sorting process.

Sorting Process

The script follows the following steps to sort the files:

  1. Parse the command-line arguments to determine the source and output folders.
  2. Use a recursive function to grab all the subfolders within the source folder.
  3. Create a separate thread for each file extension found in the source folder.
  4. Each thread waits until all subfolders have been grabbed before starting the sorting process.
  5. Each thread handles its assigned file extension by creating a corresponding folder in the output directory and copying the files with that extension.
  6. Once all threads have finished processing, the script completes.

Example

To sort files in the "TestFolder" directory and place the sorted files in the "dist" directory, you can run the script with the following command:

python sort_folder.py --source TestFolder --output dist

Note

Before deleting the old folder, ensure that the sorting process has completed successfully and that the files have been copied to the desired output folder.

Please feel free to modify and adapt this script according to your needs.

folder_sorter_threads's People

Contributors

remmover avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.