Skip to main content

Lightweight file management utilities for deduplication and organization

Project description

fileherder

Lightweight File Management Utilities

A focused Python package for essential file management operations without heavy dependencies.

Features

  • Duplicate Detection - Hash-based duplicate finding with SHA256
  • File Organization - Automatic categorization by file type
  • Batch Operations - Safe move, copy, delete, and rename operations
  • Type Detection - Smart file type classification
  • Rich CLI - Beautiful terminal interface (optional)
  • Zero Required Dependencies - Core functionality works standalone

Installation

# Basic installation (no dependencies)
pip install fileherder

# With Rich CLI (recommended)
pip install fileherder[cli]

# Development install
pip install fileherder[dev]

Quick Start

Command Line

# Find duplicate files
fileherder duplicates /path/to/directory

# Find duplicate images larger than 1MB
fileherder duplicates /photos --min-size 1048576 --extensions .jpg,.png

# Organize directory by file type
fileherder organize /downloads

# Show directory statistics
fileherder stats /data

Python API

from fileherder import FileHerder

# Create herder instance
herder = FileHerder()

# Find duplicates
duplicates = herder.find_duplicates(
    Path("/data"),
    min_size=1024*1024,  # Files larger than 1MB
    extensions={'.jpg', '.png'}  # Only images
)

for group in duplicates:
    print(f"Found {group.count} duplicates:")
    print(f"  Wasted space: {group.waste_size} bytes")
    for file_path in group.files:
        print(f"  - {file_path}")

# Organize directory
result = herder.organize(Path("/downloads"))
print(f"Organized {result.files_organized} files")
print(f"Categories: {', '.join(result.categories_created)}")

# Get statistics
stats = herder.get_statistics(Path("/data"))
print(f"Total files: {stats['total_files']}")
print(f"Total size: {stats['total_size_mb']:.2f} MB")

File Type Categories

fileherder automatically categorizes files into:

  • code - Python, JavaScript, Java, C++, etc.
  • document - PDF, DOCX, MD, TXT, etc.
  • image - JPG, PNG, GIF, SVG, etc.
  • video - MP4, AVI, MKV, MOV, etc.
  • audio - MP3, WAV, FLAC, OGG, etc.
  • archive - ZIP, TAR, GZ, 7Z, etc.
  • data - CSV, JSON, XML, SQL, etc.
  • text - Plain text, logs, config files
  • other - Uncategorized files

API Reference

Core Classes

FileHerder

Unified interface for all file management operations.

from fileherder import FileHerder

herder = FileHerder()

# Find duplicates
duplicates = herder.find_duplicates(directory, recursive=True, min_size=0)

# Organize by type
result = herder.organize(directory, dry_run=False)

# Detect file type
file_type = herder.detect_type(file_path)

# Get statistics
stats = herder.get_statistics(directory)

DuplicateFinder

Specialized duplicate file detection.

from fileherder import DuplicateFinder

finder = DuplicateFinder()
duplicates = finder.find_duplicates(
    directory,
    recursive=True,
    min_size=1024*1024,
    extensions={'.jpg', '.png'}
)

FileOrganizer

Directory organization by file type.

from fileherder import FileOrganizer

organizer = FileOrganizer()
result = organizer.organize_directory(
    directory,
    dry_run=False,
    create_subdirs=True
)

FileTypeDetector

File type classification.

from fileherder import FileTypeDetector

detector = FileTypeDetector()
file_type = detector.detect_type(Path("script.py"))
# Returns: 'code'

Batch Operations

from fileherder.operations import (
    move_files,
    copy_files,
    delete_files_safe,
    rename_files_batch
)

# Move files
result = move_files(
    files=[Path("file1.txt"), Path("file2.txt")],
    destination=Path("/archive"),
    overwrite=False
)

# Delete safely (with confirmation)
result = delete_files_safe(
    files=duplicate_files,
    require_confirmation=True
)

Data Classes

DuplicateGroup

@dataclass
class DuplicateGroup:
    hash_value: str              # SHA256 hash
    files: List[Path]            # List of duplicate files
    total_size: int              # Combined size of all
    waste_size: int              # Size of redundant copies
    count: int                   # Number of duplicates

OrganizationResult

@dataclass
class OrganizationResult:
    files_organized: int
    categories_created: List[str]
    category_counts: Dict[str, int]
    success: bool
    error: Optional[str]

Development

# Clone repository
git clone https://github.com/lukesteuber/fileherder.git
cd fileherder

# Install with dev dependencies
pip install -e .[dev]

# Run tests
pytest tests/ -v

# Run tests with coverage
pytest tests/ --cov=fileherder --cov-report=html

Architecture

fileherder is designed with minimal dependencies:

  • Core module (core.py) - Pure Python, no dependencies
  • Operations module (operations.py) - Batch file operations
  • CLI module (cli.py) - Optional Rich interface

This allows the package to be used in environments where installing dependencies is difficult, while still offering a beautiful CLI when Rich is available.

Extracted from cleanupx

fileherder contains the core file management features from the larger cleanupx project, without AI dependencies or complex integrations.

License

MIT License

Copyright (c) 2024 Luke Steuber

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Author

Luke Steuber

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

fileherder-1.0.0.tar.gz (21.7 kB view details)

Uploaded Source

Built Distribution

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

fileherder-1.0.0-py3-none-any.whl (22.1 kB view details)

Uploaded Python 3

File details

Details for the file fileherder-1.0.0.tar.gz.

File metadata

  • Download URL: fileherder-1.0.0.tar.gz
  • Upload date:
  • Size: 21.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for fileherder-1.0.0.tar.gz
Algorithm Hash digest
SHA256 70137ec25b7b9d7e061e8d90098e8caf2a57e384a91bfaffe5d055917bc097d2
MD5 0beacea344cf841ccf6ef84809ced53e
BLAKE2b-256 ae7ee679c106b7ec404ae51aa5b07d503bba9e7b57864cd989f783577eb2d532

See more details on using hashes here.

File details

Details for the file fileherder-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: fileherder-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 22.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for fileherder-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 78f2521dc67524c66e0a9a9a95c586fb49f3002cee118062ab169521d3d9c9f5
MD5 244ddb5081e09cf04bce386df7cd19b8
BLAKE2b-256 4b7f1611029145f06f7e4532921d92ee6f0f73db34f979b586d60526f0ae38fd

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