Skip to content

Latest commit

 

History

History
113 lines (89 loc) · 3.23 KB

README.md

File metadata and controls

113 lines (89 loc) · 3.23 KB

Here’s a sample README.md for your file processor project:


File Processor

This Python project automates the organization of files based on their types by classifying them into designated folders. It serves as a simple workflow for managing and organizing files, making it an excellent beginner-friendly project to learn Python concepts like file handling and directory management.


Features

  • Scans a source folder for files.
  • Classifies files into categories based on their extensions:
    • .txt files are moved to the Text/ folder.
    • .csv files are moved to the csv/ folder.
    • Image files (.jpg, .jpeg, .png) are moved to the Images/ folder.
  • Skips directories and processes only files.
  • Handles unknown file types gracefully by logging them as "unknown."

Project Structure

file_processor/
├── input_files/          # Source folder containing files to be processed
├── Text/                 # Destination folder for text files
├── Images/               # Destination folder for image files
├── csv/                  # Destination folder for CSV files
├── file_processor.py     # Main script for processing files

Requirements

  • Python 3.6 or higher
  • Standard Python libraries: os, shutil

Setup

  1. Clone the repository or download the script to your local machine.
  2. Place all files to be processed in the input_files/ directory.
  3. Create the following folders in the project directory (if they don’t already exist):
    • Text/
    • Images/
    • csv/
  4. Install Python if you don’t have it already.

Usage

  1. Navigate to the project directory in your terminal.
  2. Run the script using the following command:
    python file_processor.py
  3. The script will:
    • Process all files in the input_files/ directory.
    • Move them to their respective folders based on file type.
    • Log a message for unknown file types.

Example Output

Input Files:

  • example.txt
  • data.csv
  • cloud.jpeg
  • README.md

Output:

  • Text/: example.txt
  • csv/: data.csv
  • Images/: cloud.jpeg
  • Console Log:
    Moved example.txt to Text
    Moved data.csv to csv
    Moved cloud.jpeg to Images
    Unknown file type: cannot move README.md
    

Customization

You can modify the script to handle additional file types or define custom folders:

  1. Edit the struc function in file_processor.py.
  2. Add new elif conditions to handle more extensions:
    elif extension == '.pdf':
        shutil.move(file_path, os.path.join("PDFs", os.path.basename(file_path)))
        print(f"Moved {file} to PDFs")

Learning Goals

This project introduces the following Python concepts:

  • File and directory operations with the os and shutil modules.
  • Conditional logic for file classification.
  • Debugging and logging outputs for script validation.

Future Improvements

  • Add support for recursive folder traversal.
  • Implement error handling for cases like file permission issues.
  • Allow configuration through a settings file (e.g., config.json).
  • Extend functionality to compress files after moving them.

Let me know if you'd like to make any tweaks!