Skip to main content

A Python 2.7/3.2+ package to sanitize filenames in a (hopefully) cross-platform, cross-filesystem manner.

Project description


A Python 2.7/3.2+ module that aims to sanitize filenames in a cross-platform, cross-filesystem manner.

Dedicated to Nadia Mahmood, my good friend Jawaad's newborn daughter. Maybe this module will be useful to her if she ever decides to follow her father's footsteps in becoming a hacker. ;-)

This is only a beginning; much work needs to be done to deal with the various filesystems' under-documented aspects.

Unlike most of the extremely naïve, whitelist-based solutions found on the Internet, this solution deals much better with Unicode filenames.

How to use

>>> from filename_sanitizer import sanitize_path_fragment
>>> crazy_filename = u'"foo/bar<bla>yada*meow?.'
>>> sanitized_filename = sanitize_path_fragment(
... crazy_filename,
... target_file_systems = {'ntfs_win32'},
... replacement = u'-'
... )
>>> print(sanitized_filename)

Read the file [`filename_sanitizer/`](filename_sanitizer/ for details of how the function deals with various file systems.


BSD 2-Clause License. See the file [LICENSE](LICENSE).

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for filename-sanitizer, version 0.1.0
Filename, size File type Python version Upload date Hashes
Filename, size filename_sanitizer-0.1.0-py3-none-any.whl (5.8 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size filename-sanitizer-0.1.0.tar.gz (4.6 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page