Converts long Windows file paths to their short 8.3 format in a string where applicable
Project description
Converts long Windows file paths to their short 8.3 format in a string where applicable.
Tested against Windows / Python 3.11 / Anaconda
pip install fullpath83replace
absolut_wpath_to_83(
string, valid_string_ends=("<", ">", ":", '"', "|", "?", "*", "\n", "\r", " ")
):
r"""
This function takes a string containing file paths and attempts to convert long
Windows file paths to their short 8.3 format where applicable. It identifies file
paths in the input string, checks if they exist, and if they do, replaces them
with their short 8.3 format versions.
Parameters:
- string (str): The input string containing file paths.
- valid_string_ends (tuple): A tuple of valid string endings 'c:\some long path' will not be converted if "'" is not in valid_string_ends
Returns:
- str: The input string with long file paths replaced by their short 8.3 format
versions, while preserving valid string endings.
Example Usage:
from fullpath83replace import absolut_wpath_to_83
string1 = r'"C:\Users\hansc\Downloads\scrapingthreading.mp4" c:\babaexistsbutnottherest "C:\Users\hansc\Downloads\Roger LeRoy Miller, Daniel K. Benjamin, Douglass C. North - The Economics of Public Issues-Pearson College Div (2017).pdf" c:\baba c:\Windows'
str1 = absolut_wpath_to_83(
string1, valid_string_ends=("<", ">", ":", '"', "|", "?", "*", "\n", "\r", " ")
)
string2 = r'C:\Users\hansc\Downloads\scrapingthreading.mp4 c:\babaexists butnot therest C:\Users\hansc\Downloads\Roger LeRoy Miller, Daniel K. Benjamin, Douglass C. North - The Economics of Public Issues-Pearson College Div (2017).pdf c:\baba "c:\Windows" '
str2 = absolut_wpath_to_83(
string2, valid_string_ends=("<", ">", ":", '"', "|", "?", "*", "\n", "\r", " ")
)
string3 = r''' C:\Users\hansc\Downloads\scrapingthreading.mp4 c:\babaxxxas\asfasdxx\bi 'C:\Users\hansc\Downloads\Roger LeRoy Miller, Daniel K. Benjamin, Douglass C. North - The Economics of Public Issues-Pearson College Div (2017).pdf' xxxxxxxxxxxxxxxxxx "c:\baba" c:\Windows'''
str3 = absolut_wpath_to_83(
string3, valid_string_ends=("<", ">", ":", '"', "|", "?", "*", "\n", "\r", " ", "'")
)
print(str1)
print(string1)
# "C:\Users\hansc\DOWNLO~1\SCRAPI~1.MP4" c:\babaexistsbutnottherest "C:\Users\hansc\DOWNLO~1\ROGERL~1.PDF" c:\baba c:\Windows
# "C:\Users\hansc\Downloads\scrapingthreading.mp4" c:\babaexistsbutnottherest "C:\Users\hansc\Downloads\Roger LeRoy Miller, Daniel K. Benjamin, Douglass C. North - The Economics of Public Issues-Pearson College Div (2017).pdf" c:\baba c:\Windows
print(str2)
print(string2)
# C:\Users\hansc\DOWNLO~1\SCRAPI~1.MP4 c:\babaexists butnot therest C:\Users\hansc\DOWNLO~1\ROGERL~1.PDF c:\baba "c:\Windows
# C:\Users\hansc\Downloads\scrapingthreading.mp4 c:\babaexists butnot therest C:\Users\hansc\Downloads\Roger LeRoy Miller, Daniel K. Benjamin, Douglass C. North - The Economics of Public Issues-Pearson College Div (2017).pdf c:\baba "c:\Windows"
print(str3)
print(string3)
# C:\Users\hansc\DOWNLO~1\SCRAPI~1.MP4 c:\babaxxxas\asfasdxx\bi 'C:\Users\hansc\DOWNLO~1\ROGERL~1.PDF' xxxxxxxxxxxxxxxxxx "c:\baba" c:\Windows
# C:\Users\hansc\Downloads\scrapingthreading.mp4 c:\babaxxxas\asfasdxx\bi 'C:\Users\hansc\Downloads\Roger LeRoy Miller, Daniel K. Benjamin, Douglass C. North - The Economics of Public Issues-Pearson College Div (2017).pdf' xxxxxxxxxxxxxxxxxx "c:\baba" c:\Windows
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file fullpath83replace-0.12.tar.gz
.
File metadata
- Download URL: fullpath83replace-0.12.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6a8358efa268140182ffebab359c3bedc5773c3ee0e8738dec61390e5931a1a4 |
|
MD5 | 85663d3f57005d2f838b4597b05b9e58 |
|
BLAKE2b-256 | 55702ca9185ae6e623b57a5f055812192623f20b017f25b2318c51cc9c54b373 |
File details
Details for the file fullpath83replace-0.12-py3-none-any.whl
.
File metadata
- Download URL: fullpath83replace-0.12-py3-none-any.whl
- Upload date:
- Size: 6.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 49ad6086e63c304a3df88703b3b07e5e3048865e6b12c4f43dabd95e185de9f8 |
|
MD5 | 75f933e950cb98943933645007ac8e08 |
|
BLAKE2b-256 | a10473dc6c5a641f0f4c7afa1837962af130368075fed82ad4c3fc863801c7e9 |