Issue with recursive folder listing for folder beyond 255 characters
Hi,
I have an application that re-curses through sub-folders and adds them to a database, I'm running into issues with a folder/path being beyond 255 characters and the code not being able to list the sub-folders for the folder.
Is anyone aware of a way to get around this issue?
The code I'm using is below, the program crashes when it reaches the first line upon reaching the folder which is 256 characters long.
Code:
Public Sub AddSubFolders(ByVal TopPath As String, ByVal TopFolderID As Integer, ByVal UNCValue As String)
'Called by StartAddSubfolders to check for sub-subfolders and add those to the database.
'The procedure recalls itself to check for further sub-folders.
Try
Dim fldInfo As New IO.DirectoryInfo(TopPath)
Dim fileObject As FileSystemInfo
Dim pstSubFolder As String
Dim dsNewRow As DataRow
For Each fileObject In fldInfo.GetDirectories()
pstSubFolder = fileObject.FullName
Debug.Print(pstSubFolder)
'Add folder to database
dsNewRow = dsSubFolder.Tables("SubFolder").NewRow()
dsNewRow.Item("TopFolderID") = TopFolderID
dsNewRow.Item("SubFolderPath") = UNCValue & Mid(pstSubFolder, 3, Len(pstSubFolder))
dsSubFolder.Tables("SubFolder").Rows.Add(dsNewRow)
'Recall Procedure
AddSubFolders(fileObject.FullName, TopFolderID, UNCValue)
Next
Catch ex As Exception
Throw New Exception("Error in Folders.AddFolders " + ex.Message)
End Try
End Sub
Any help would be much appreciated.
Thanks,
Re: Issue with recursive folder listing for folder beyond 255 characters
Sorry, it doesn't actually crash at the first line it crashes at "For Each fileObject In fldInfo.GetDirectories()".
Thanks,
Re: Issue with recursive folder listing for folder beyond 255 characters