Hi there,
I am stuck at the moment with a sillyissue, i am using a file searcher in vb to inventory a drive and it stops as soon as it hits a protected file.
i need it to be able to skip the file or folder and resume the next target, now you would think a
Tag would solve this but its not. here is my code:Code:On Error Resume Next
Search Method:
Code:Imports System.IOCode:Sub Search(ByVal RootDir As IO.DirectoryInfo) For Each File In RootDir.GetFiles(txt_target.Text) lstMusicFiles.Items.Add(File.FullName) 'process the file Current_DIR.Text = (File.Directory.Name) Current_FILE.Text = (File.Name) names = File.Name lstMusicFiles.Update() Me.Update() Next For Each SubDir In RootDir.GetDirectories() Search(SubDir) Next End SubIf any one can help i would much appreciate it, thank you.Code:Private Sub start() Dim RootDir As New IO.DirectoryInfo(txt_path.Text) Try Search(RootDir) Catch ex As Exception errorh.error_console.Text = (vbCrLf & "Scan Aborted because of the following Error: " & ex.Message) txt_error.Text = "Scan Finished @ " & DateAndTime.Now End Try If lstMusicFiles.Items.Count <= 0 Then txt_error.Text = "No Target Files Found at Target Path." Else End If results.GroupBox1.Visible = True End Sub![]()
You simply need to refine a few things in your code
You may have to refine it to better fit you but the main thing is when you call the sub you don't want to try/catch it because than an error in the sub just exits the sub basically, by adding the try catch into the sub and not try catching when calling it, you allow the search to continue I included an example projectCode:Sub Search(ByVal RootDir As IO.DirectoryInfo) 'Just added a try catch to make the search continue try For Each File In RootDir.GetFiles(txt_target.Text) lstMusicFiles.Items.Add(File.FullName) 'process the file Current_DIR.Text = (File.Directory.Name) Current_FILE.Text = (File.Name) names = File.Name lstMusicFiles.Update() Me.Update() Next catch end try 'You forgot are trying to do something that doesnt exist here For Each SubDir In RootDir.GetDirectories() Search(SubDir) Next 'so change it to this DIm SUBDIRS() as string = rootdir.getdirectories try for each SubDir as string in SUBDIRS search(subdir) next catch ' catch the exception to continue searching end try End Sub
Multiupload.com - upload your files to multiple file hosting sites!
Thank you so much, it works like a treat! Only thing i changed was the catch for subdir scanning which i set to :
Cheers!Code:Try For Each SubDir In RootDir.GetDirectories() Search(SubDir) Next Catch End Try![]()
Glad I could help
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks