Need help working with long paths

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!