escape-windows-filepath


Nameescape-windows-filepath JSON
Version 0.10 PyPI version JSON
download
home_pagehttps://github.com/hansalemaos/escape_windows_filepath
SummaryEscaping file paths (Windows) without crying and losing one's mind
upload_time2023-04-03 00:37:18
maintainer
docs_urlNone
authorJohannes Fischer
requires_python
licenseMIT
keywords path pathlib escaping os window file folder
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
# Escaping file paths (Windows) without crying and losing one's mind



## pip install escape-windows-filepath



### Tested against Windows 10 / Python 3.10 / Anaconda 



```python

# 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



```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/hansalemaos/escape_windows_filepath",
    "name": "escape-windows-filepath",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "path,pathlib,escaping,os,window,file,folder",
    "author": "Johannes Fischer",
    "author_email": "<aulasparticularesdealemaosp@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/82/c4/d58c5155e0bca3db9d098fabddf0e79a41bf802d5c9dcf9d96714991ce54/escape_windows_filepath-0.10.tar.gz",
    "platform": null,
    "description": "\r\n# Escaping file paths (Windows) without crying and losing one's mind\r\n\r\n\r\n\r\n## pip install escape-windows-filepath\r\n\r\n\r\n\r\n### Tested against Windows 10 / Python 3.10 / Anaconda \r\n\r\n\r\n\r\n```python\r\n\r\n# How it is usually done:\r\n\r\nimport os\r\n\r\nvideopathraw = r\"C:\\baba ''bubu\\bab xx\\2020-11-23 13-05-26.mp4\"\r\n\r\nvlcpathraw = r\"C:\\Program Files\\VideoLAN\\VLC\\vlc.exe\"\r\n\r\n\r\n\r\n# Quite frequently something like this surprisingly works, but in this example it doesn't:\r\n\r\nvideofilenotwellescaped = '\"' + r\"C:\\baba ''bubu\\bab xx\\2020-11-23 13-05-26.mp4\" + '\"'\r\n\r\nvlcpathnotwellescaped = '\"' + r\"C:\\Program Files\\VideoLAN\\VLC\\vlc.exe\" + '\"'\r\n\r\nescapedcmdnotgood = rf\"{vlcpathnotwellescaped} {videofilenotwellescaped}\"\r\n\r\nprint(f\"{escapedcmdnotgood=}\")\r\n\r\nos.system(escapedcmdnotgood)\r\n\r\n\r\n\r\n# Output:\r\n\r\n# escapedcmdnotgood='\"C:\\\\Program Files\\\\VideoLAN\\\\VLC\\\\vlc.exe\" \"C:\\\\baba \\'\\'bubu\\\\bab xx\\\\2020-11-23 13-05-26.mp4\"'\r\n\r\n# 'C:\\Program' is not recognized as an internal or external command,\r\n\r\n# operable program or batch file.\r\n\r\n\r\n\r\n\r\n\r\nfrom escape_windows_filepath import escape_windows_path\r\n\r\n\r\n\r\n# The safest method is escaping evey single part (folder,file) of the path\r\n\r\nvideofileescaped = escape_windows_path(videopathraw)\r\n\r\nvlcpath = escape_windows_path(vlcpathraw)\r\n\r\nescapedcmd = rf\"{vlcpath} {videofileescaped}\"\r\n\r\nprint(f\"{escapedcmd=}\")\r\n\r\nos.system(escapedcmd)\r\n\r\n# Output\r\n\r\n# escapedcmd='C:\\\\\"Program Files\"\\\\\"VideoLAN\"\\\\\"VLC\"\\\\\"vlc.exe\" C:\\\\\"baba \\'\\'bubu\"\\\\\"bab xx\"\\\\\"2020-11-23 13-05-26.mp4\"'\r\n\r\n# And the video player opens\r\n\r\n\r\n\r\n```\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Escaping file paths (Windows) without crying and losing one's mind",
    "version": "0.10",
    "project_urls": {
        "Homepage": "https://github.com/hansalemaos/escape_windows_filepath"
    },
    "split_keywords": [
        "path",
        "pathlib",
        "escaping",
        "os",
        "window",
        "file",
        "folder"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ae1267d81ee2928087d6c4eecdc487001d4df73bc6d12be08697449afa2320d9",
                "md5": "4b4f201665fc404c8706bcd82dd3a926",
                "sha256": "d1eeb761460c9498008157abc8851e0a64e39270e256ac59215f89773bd015f3"
            },
            "downloads": -1,
            "filename": "escape_windows_filepath-0.10-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "4b4f201665fc404c8706bcd82dd3a926",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 5328,
            "upload_time": "2023-04-03T00:37:16",
            "upload_time_iso_8601": "2023-04-03T00:37:16.181769Z",
            "url": "https://files.pythonhosted.org/packages/ae/12/67d81ee2928087d6c4eecdc487001d4df73bc6d12be08697449afa2320d9/escape_windows_filepath-0.10-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "82c4d58c5155e0bca3db9d098fabddf0e79a41bf802d5c9dcf9d96714991ce54",
                "md5": "0b733aab274f2d372f15c30ece461ddf",
                "sha256": "831e331521a3881ed11bc603a5c8709b4c27507ad3482256ae8a6cb7b85d84bf"
            },
            "downloads": -1,
            "filename": "escape_windows_filepath-0.10.tar.gz",
            "has_sig": false,
            "md5_digest": "0b733aab274f2d372f15c30ece461ddf",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 3539,
            "upload_time": "2023-04-03T00:37:18",
            "upload_time_iso_8601": "2023-04-03T00:37:18.470182Z",
            "url": "https://files.pythonhosted.org/packages/82/c4/d58c5155e0bca3db9d098fabddf0e79a41bf802d5c9dcf9d96714991ce54/escape_windows_filepath-0.10.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-04-03 00:37:18",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "hansalemaos",
    "github_project": "escape_windows_filepath",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "escape-windows-filepath"
}
        
Elapsed time: 0.38557s