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
fullpath83replace-0.10.tar.gz
(4.5 kB
view hashes)
Built Distribution
Close
Hashes for fullpath83replace-0.10-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7fd5b3d682746fd2ec6f6c388d4ed0948f939e11279ed66ef4e3fe3b04f372a2 |
|
MD5 | 1d89e70bc3e2b6f20798ca4aed88141f |
|
BLAKE2b-256 | 764e8b847aa451c1b7d7bbc263cb6ff06c5fc26bfc98839c9ba64379aba7a083 |