Need help working with long paths

Hey!

I’m working on a solution that lists folders and files of a given folder. Sometimes a given folder has such a complex and deep structure that a PathTooLongException occurs (maximum 260 characters or 248 for directories). Unfortunately I may not rename files or folders to reduce path length. In fact, I don’t have any influence on given folders. I just have to deal with the long paths.

I tried

  • researching the problem in UiPath Forum, but most answers are bots praising long path tool - doesn’t fit my requirement
  • an alternate way to get paths with PowerShell script instead of VB .Net - same error!
  • Using the \\?\ prefix to use Windows API without path length limit (i think?), but now characters in the path (e.g. dots (.)) are invalid :face_with_raised_eyebrow:
  • Setting RegistryKey for LongPathEnabled as described here, but I didn’t get the application manifest part and it didn’t work on its own - do I have to edit Studio.manifest?!

I also stumbled upon the ExtendedFileInfo library that looks like it could help, but sadly I am clueless how to implement this into my UiPath flow.

Any help is greatly appreciated!
Cheers

1 Like

Do you guys have an idea? @vvaidya @ClaytonM @bcorrea

Thanks for your time!

Maybe this will help, if you really have paths bigger than 260:

2 Likes

I’m not really sure because I haven’t dealt with the longfilepath issue since earlier versions of Windows, but that link provided by bcorrea has some good info. You may need to set the currentdirectory then use the relative path in order to shorten.

1 Like

Thank you for the input!

@bcorrea I really do have paths longer than 260 characters, @ClaytonM even when I use the relative paths. The given folder structure is really stupifyingly complex.

I read up on the Microsoft documentation and actually tried the thing with the registry key:

Can you make sense of the application manifest part?

I have the exact same problem.

This issue was really weird. After IT couldn’t help me with the LongPathEnabled thing, I found a workaround that felt like I tricked the system :rofl:

Unfortunately I don’t have access to the code anymore, but here is what I recall:

Whenever I found a path that was too long, I took the first 260/248 characters of the fully qualified path, then checked for the last index of a backslash and wrote the left and the right part of the path separated by that backslash to variables.

Against recommendation I mapped that left part of the path to a temporary network drive letter like this! Combined with the right part of the path I was able to fabricate a much shorter path to the desired file or directory. The temporary drive letter saved up to 257 characters from the fully qualified path, thus almost doubling my effective maximum path length! Good enough for my usecase!

After I was done working with a file or directory path I disconnected the temporary drive again with something like this. I didn’t stress test this solution, but you should probably make sure to have some time inbetween connecting and disconnecting the temporary network drive.

If you have a modern IT department you should probably look into the LongPathEnabled option for a more reliable and futureproof solution though.

Happy Automating!

Closed as it was attracting spam.