PathTooLongException

  • Thread starter Thread starter Gillard
  • Start date Start date
G

Gillard

hi ,
i try to

io.file.delete(startmenushortcut)
i get PathTooLongException

how to delete those dead links in my start menu
please
 
thank you kimi but I know that

my problem is to delete the files that have a too long path
 
thank you kimi but I  know that

my problem is to delete the files that have a too long path









- Show quoted text -

Well, are you able to reduce file name by renaming with
"My.Computer.Filesystem.RenameFile"? Then try to delete.

If renaming file to a smaller name does not help, try also renaming
directories along that path to fit the whole path in 250 char scale.

Hope this helps,

Onur Güzel
 
thank you very much Tom
that's all right now


Tom Shelton said:
If that's the case, then in this situation you'll have to resort to using
P/Invoke and the DeleteFile api. You can not delete a file with the .NET
functions that exceeds MAX_PATH - which is defined as 260 characters, even
though NTFS supports paths as long as 32k characters.

Here is the declare for the DeleteFile api:

Declare Auto Function DeleteFile Lib "kernel32" ( _
ByVal lpFilePath As String) As Boolean

Now, simply declaring and using this API won't work either - because the
file
api's also by default enforce the traditional MAX_PATH value. So, to
actually
get the function to delete a long path, you have to pre-append the value
"\\?\" to the path.

For example:

Dim p As String = "\\?\C:\Test\SomeFile.Txt"
If Not DeleteFile (p) Then
Throw New
System.ComponentModel.Win32Exception(Marshal.GetLastWin32Error())
End If

If you want a lot more information on this, just google MAX_PATH and .NET
:)
 
Back
Top