First, I'll admit up front that programming is definately not one of my strong points as I am basically self taught just enough to get some tasks completed. Still, I've managed to build a small program in VB .net 2008 that'll search specified folders or server shares for specific folders, report back various information, and write the output to a .csv file.
I've been able to resolve all but one problem. Every time this search method comes across a long folder name (which I know is too long) the entire search bombs. My work around is to nest the search function within a search function and for each statement so that the upper level search doesn't stop and then, by using a try catch statement, it logs the error to be fixed later.
For example, here’s a simplified version, minus all the other variables.
[blue]Private Function[/blue] SearchRootFolders()
[blue]Dim[/blue] StartDir [blue]As[/blue] New DirectoryInfo(SearchPath)
[blue]Dim[/blue] NextDir [blue]As[/blue] DirectoryInfo() = StartDir.GetDirectories()
[blue]Dim[/blue] FoundDirectory [blue]As[/blue] DirectoryInfo
[blue]For Each[/blue] FoundDirectory [blue]In[/blue] NextDir
[blue]Try[/blue]
GetFolders(FoundDirectory.FullName, [red]"variable text"[/red], IO.SearchOption.AllDirectories)
[blue]Catch[/blue] ex [blue]As[/blue]system.IO.DirectoryNotFoundException
[error handling subs]
[blue]Catch[/blue] ex [blue]As[/blue] IOException
[ererror handling subs]
[blue]End Try[/blue]
[blue]Next[/blue] FoundDirectory
The first statement calls another search search statement to provent it from stopping the entire search.
[blue]Private Function[/blue] GetFolders([blue]ByVal[/blue] path [blue]As String[/blue], [blue]ByVal[/blue] searchPattern [blue]As String[/blue], [blue]ByVal[/blue] searchoption [blue]As SearchOption[/blue])
[blue]Dim[/blue] dirs = Directory.GetDirectories(path, searchPattern, searchoption)
[blue]For Each[/blue] Folder [blue]In[/blue] dirs
GetFiles(Folder, "*", IO.SearchOption.AllDirectories)
[blue]Next[/blue]
here's an example of the err.description associated:
Could not find a part of the path '\\sever\share\userdirectory\Old My documents\Solutions\You receive a 0x800A01AE error message or a 0x080070570 error message when you try to connect to the Windows Update Web page or to the Microsoft Update Web page in Windows Server 2003 or Windows XP_files'.
Currently I'm using: System.IO.Directory.GetDirectories(path, searchPattern, searchoption) to search the file system. Is there a better method for this?
Honestly, it's not that big a deal. Truth is, these long folder names need to be cleaned up anyway, but... We'll leave to one of the other guys, right? kidding.
Any suggestions? I'd like to find a way to log the error but continue the search of that folder and subdirectories. I've thought about reading up on other languages to see if they will likely be limited to the same number of characters in a folder name, but haven't found much thus far. Any ideas would be aprecreated.
Thanks all.
I've been able to resolve all but one problem. Every time this search method comes across a long folder name (which I know is too long) the entire search bombs. My work around is to nest the search function within a search function and for each statement so that the upper level search doesn't stop and then, by using a try catch statement, it logs the error to be fixed later.
For example, here’s a simplified version, minus all the other variables.
[blue]Private Function[/blue] SearchRootFolders()
[blue]Dim[/blue] StartDir [blue]As[/blue] New DirectoryInfo(SearchPath)
[blue]Dim[/blue] NextDir [blue]As[/blue] DirectoryInfo() = StartDir.GetDirectories()
[blue]Dim[/blue] FoundDirectory [blue]As[/blue] DirectoryInfo
[blue]For Each[/blue] FoundDirectory [blue]In[/blue] NextDir
[blue]Try[/blue]
GetFolders(FoundDirectory.FullName, [red]"variable text"[/red], IO.SearchOption.AllDirectories)
[blue]Catch[/blue] ex [blue]As[/blue]system.IO.DirectoryNotFoundException
[error handling subs]
[blue]Catch[/blue] ex [blue]As[/blue] IOException
[ererror handling subs]
[blue]End Try[/blue]
[blue]Next[/blue] FoundDirectory
The first statement calls another search search statement to provent it from stopping the entire search.
[blue]Private Function[/blue] GetFolders([blue]ByVal[/blue] path [blue]As String[/blue], [blue]ByVal[/blue] searchPattern [blue]As String[/blue], [blue]ByVal[/blue] searchoption [blue]As SearchOption[/blue])
[blue]Dim[/blue] dirs = Directory.GetDirectories(path, searchPattern, searchoption)
[blue]For Each[/blue] Folder [blue]In[/blue] dirs
GetFiles(Folder, "*", IO.SearchOption.AllDirectories)
[blue]Next[/blue]
here's an example of the err.description associated:
Could not find a part of the path '\\sever\share\userdirectory\Old My documents\Solutions\You receive a 0x800A01AE error message or a 0x080070570 error message when you try to connect to the Windows Update Web page or to the Microsoft Update Web page in Windows Server 2003 or Windows XP_files'.
Currently I'm using: System.IO.Directory.GetDirectories(path, searchPattern, searchoption) to search the file system. Is there a better method for this?
Honestly, it's not that big a deal. Truth is, these long folder names need to be cleaned up anyway, but... We'll leave to one of the other guys, right? kidding.
Any suggestions? I'd like to find a way to log the error but continue the search of that folder and subdirectories. I've thought about reading up on other languages to see if they will likely be limited to the same number of characters in a folder name, but haven't found much thus far. Any ideas would be aprecreated.
Thanks all.