Skip to main content

Drop-in replacement for shutil with long path support for Windows

Project description

LongPathShutil

LongPathShutil is a drop-in Python wrapper for the methods of the built-in shutil library, providing enhanced support for long file paths on Windows. It leverages the \\?\ prefix to bypass the 260-character path length limit on Windows systems, and to be able to handle deeply nested or long file names. More info on the long path limitations on windows here

Features

  • Seamlessly integrates long path support on Windows.
  • Fully compatible with the existing shutil functions. The functions only.
  • Automatically prefixes paths with \\?\ when necessary.
  • Offers functions to enable or disable long path support via the Windows registry at least for the applications supporting it. (Needs to be executed as admin)

Installation

You can install it like so:

pip install LongPathShutil

Usage

Enabling Long Paths in the Windows Registry

You can try programmatically enabling long paths via the registry. This does however require admin access and does not always work. Otherwise you can use the module as drop-in replacement for shutil on windows.

import LongPathShutil

# Enable long paths in the Windows registry (requires administrative privileges)
LongPathShutil.enable_long_paths_on_registry()

Basic File Operations

import LongPathShutil as shutil

# Copy a file with long paths
shutil.copy(r"C:\very\long\source\path\file.txt", r"C:\another\very\long\destination\path\file.txt")

# Move a directory with long paths
shutil.move(r"C:\very\long\source\directory", r"C:\another\very\long\destination\directory")

# Remove a directory tree with long paths
shutil.rmtree(r"C:\very\long\path\to\directory")

Full API

The LongPathShutil class provides all the functions available in shutil with the addition of long path support:

  • copyfile(), copy(), copy2()
  • move(), rmtree(), copytree()
  • make_archive(), unpack_archive(), get_archive_formats(), and more.

See the complete list of functions here.

Why Use LongPathShutil?

By default, Windows imposes a 260-character limit on paths, which can cause problems when dealing with deeply nested directory structures or long filenames. This module automatically adds the necessary prefix to bypass this limitation, allowing for seamless file operations across various platforms.

Contributing

If you find a bug or have a suggestion, feel free to open an issue or submit a pull request. Make sure to check the CONTRIBUTING.md for guidelines.

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

longpathshutil-0.5.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

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

longpathshutil-0.5-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file longpathshutil-0.5.tar.gz.

File metadata

  • Download URL: longpathshutil-0.5.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for longpathshutil-0.5.tar.gz
Algorithm Hash digest
SHA256 53982f8d69e1da6e74b8c92f52c2819c55362cb478db281b8eab9fea3734a635
MD5 881b6eea6f4629e26b8235aec79bedf1
BLAKE2b-256 83f1cb06abb63884be7ebb704ad157d56c17c44bc94a163943db192394dee92f

See more details on using hashes here.

Provenance

The following attestation bundles were made for longpathshutil-0.5.tar.gz:

Publisher: ci.yml on simonmb/LongPathShutil

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file longpathshutil-0.5-py3-none-any.whl.

File metadata

  • Download URL: longpathshutil-0.5-py3-none-any.whl
  • Upload date:
  • Size: 4.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for longpathshutil-0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 efdafbdf86501899a8262fdefcd278578302ff98004d5be945de06a7fc509401
MD5 e69b64610fa438f47e047a054542c53e
BLAKE2b-256 ac13695e02c2a5e3ebfde950b0e3fcc9c76d6fb34d89e3dfb8438dcc7dcb4ba0

See more details on using hashes here.

Provenance

The following attestation bundles were made for longpathshutil-0.5-py3-none-any.whl:

Publisher: ci.yml on simonmb/LongPathShutil

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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