Using long paths in Visual Basic

527 views Asked by At

I use the Directory.getLastWriteTimeUtc() method. If the path is too long for this method it throws an PathTooLongException. So I started to use Google finding a solution for this problem. A couple of search results adviced me to use \\?\ as a prefix. Using the Windows Explorer this solution works perfectly. But it does not work with Visual Basic. Adding this prefix to the path the result is an ArgumentException because the is an illegal character in the path.

So I want to ask you if you have a solution to handle long paths with Visual Basic.

The snippet of code that causes the problem is the following one. It is used to get the most recent file of a folder.

Oh, I'm sorry. Of course I will show you my snippet of code that causes the problem.

Try
If Directory.GetLastWriteTimeUtc(s) > Directory.GetLastWriteTimeUtc(latest) Then
latest = s
End If
Catch e As PathTooLongException
 Console.WriteLine("error...")
End Try
1

There are 1 answers

0
jp_ On

I solved the problem by subsitute the Delimon.Win32.IO for the System.IO library. Now I can handle such long paths. Hope I can help anyone later.