Friday, July 30, 2021

Windows short/abbreviated path to long using Python pathlib.resolve()

Some Python packages generate a Windows shortened path. For instance, a call to tempfile.TemporaryDirectory generates a url like "C:\Users\STEPHE~1.BEA\AppData\Local\Temp\company_r85o5axn".

Unfortunately, some other processes have trouble with this shortened path and will fail with file not found errors.

The solution to this problem lies in Python's pathlib module. Calling .resolve() on any Path will get you the fully elongated path!

To get the fully elongated path simply:

long_file_name = Path("C:\Users\STEPHE~1.BEA\AppData\Local\Temp\company_r85o5axn").resolve()

No comments:

Post a Comment