troubleshooting Question

Long file paths with pywin32 Python library

Avatar of meirionwyllt
meirionwyllt asked on
Python
6 Comments1 Solution15 ViewsLast Modified:
When attempting to use “excel.Workbooks.Open(filepath)” with pywin32 when the file paths are longer than 259 characters, I get an error saying that the path is too long. It works OK if the path is 254 characters.

With the Pandas library, for example, I've been able to get around the problem by prefixing the file paths with “\\?\”, but unable to do that with pywin32.

I've enabled the following local group policy setting https://docs.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=cmd and whilst it did make a difference to Pandas (since then I don't need to use the prefix “\\?\” at all), it's made no difference to pywin32.

Any ideas of how I can get around this (apart from reducing the file path lengths).

Thanks.
ASKER CERTIFIED SOLUTION
David H.H.Lee
Digital Marketing (Hospitality)
Join our community to see this answer!
Unlock 1 Answer and 6 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros