Escaping file paths (Windows) without crying and losing one's mind
pip install escape-windows-filepath
Tested against Windows 10 / Python 3.10 / Anaconda
# How it is usually done:
import os
videopathraw = r"C:\baba ''bubu\bab xx\2020-11-23 13-05-26.mp4"
vlcpathraw = r"C:\Program Files\VideoLAN\VLC\vlc.exe"
# Quite frequently something like this surprisingly works, but in this example it doesn't:
videofilenotwellescaped = '"' + r"C:\baba ''bubu\bab xx\2020-11-23 13-05-26.mp4" + '"'
vlcpathnotwellescaped = '"' + r"C:\Program Files\VideoLAN\VLC\vlc.exe" + '"'
escapedcmdnotgood = rf"{vlcpathnotwellescaped} {videofilenotwellescaped}"
print(f"{escapedcmdnotgood=}")
os.system(escapedcmdnotgood)
# Output:
# escapedcmdnotgood='"C:\\Program Files\\VideoLAN\\VLC\\vlc.exe" "C:\\baba \'\'bubu\\bab xx\\2020-11-23 13-05-26.mp4"'
# 'C:\Program' is not recognized as an internal or external command,
# operable program or batch file.
from escape_windows_filepath import escape_windows_path
# The safest method is escaping evey single part (folder,file) of the path
videofileescaped = escape_windows_path(videopathraw)
vlcpath = escape_windows_path(vlcpathraw)
escapedcmd = rf"{vlcpath} {videofileescaped}"
print(f"{escapedcmd=}")
os.system(escapedcmd)
# Output
# escapedcmd='C:\\"Program Files"\\"VideoLAN"\\"VLC"\\"vlc.exe" C:\\"baba \'\'bubu"\\"bab xx"\\"2020-11-23 13-05-26.mp4"'
# And the video player opens
Metadata
Release files for escape-windows-filepath 0.10
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| escape_windows_filepath-0.10.tar.gz | 3.5 kB | Without provenance | Details for escape_windows_filepath-0.10.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| escape_windows_filepath-0.10-py3-none-any.whl | Python 3 | none | any | Details for escape_windows_filepath-0.10-py3-none-any.whl |
Total release size: 8.9 kB
Release files / escape_windows_filepath-0.10.tar.gz
| Download URL | escape_windows_filepath-0.10.tar.gz |
|---|---|
| Size | 3.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
831e331521a3881ed11bc603a5c8709b4c27507ad3482256ae8a6cb7b85d84bf
|
|
BLAKE2b-256 checksum How to use checksums |
82c4d58c5155e0bca3db9d098fabddf0e79a41bf802d5c9dcf9d96714991ce54
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.10
|
Release files / escape_windows_filepath-0.10-py3-none-any.whl
| Download URL | escape_windows_filepath-0.10-py3-none-any.whl |
|---|---|
| Size | 5.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d1eeb761460c9498008157abc8851e0a64e39270e256ac59215f89773bd015f3
|
|
BLAKE2b-256 checksum How to use checksums |
ae1267d81ee2928087d6c4eecdc487001d4df73bc6d12be08697449afa2320d9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.10
|
Security for escape-windows-filepath 0.10
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.