+ Reply to Thread
Results 1 to 4 of 4

Thread: How to skip Protected Directories and Files in a Inventory Scan

  1. #1
    Newbie Sharper_Software will become famous soon enough Sharper_Software's Avatar
    Join Date
    Mar 2010
    Location
    Melbourne, Australia
    Posts
    13
    Blog Entries
    1

    Question How to skip Protected Directories and Files in a Inventory Scan

    Hi there,

    I am stuck at the moment with a silly issue, 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

    Code:
    On Error Resume Next
    Tag would solve this but its not. here is my code:

    Search Method:

    Code:
    Imports System.IO
    Code:
        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 Sub
    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
    If any one can help i would much appreciate it, thank you.

  2. #2
    Newbie Abis24 is an unknown quantity at this point
    Join Date
    May 2010
    Posts
    3

    Re: How to skip Protected Directories and Files in a Inventory Scan

    Quote Originally Posted by Sharper_Software View Post
    Hi there,

    I am stuck at the moment with a silly issue, 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

    Code:
    On Error Resume Next
    Tag would solve this but its not. here is my code:

    Search Method:

    Code:
    Imports System.IO
    Code:
        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 Sub
    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
    If any one can help i would much appreciate it, thank you.
    You simply need to refine a few things in your code

    Code:
        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
    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 project

    Multiupload.com - upload your files to multiple file hosting sites!

  3. #3
    Newbie Sharper_Software will become famous soon enough Sharper_Software's Avatar
    Join Date
    Mar 2010
    Location
    Melbourne, Australia
    Posts
    13
    Blog Entries
    1

    Re: How to skip Protected Directories and Files in a Inventory Scan

    Thank you so much, it works like a treat! Only thing i changed was the catch for subdir scanning which i set to :
    Code:
     Try
                For Each SubDir In RootDir.GetDirectories()
                    Search(SubDir)
                Next
            Catch
            End Try
    Cheers!

  4. #4
    Newbie Abis24 is an unknown quantity at this point
    Join Date
    May 2010
    Posts
    3

    Re: How to skip Protected Directories and Files in a Inventory Scan

    Glad I could help

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. Visual Basic List Files and Directories in Root
    By QuackWare in forum Classes and Code Snippets
    Replies: 0
    Last Post: 01-24-2010, 10:02 PM
  2. drm protected wma files in linux
    By Off in forum Linux Applications
    Replies: 4
    Last Post: 01-19-2009, 06:58 AM
  3. Scan files in directory
    By ly0ha in forum ionFiles
    Replies: 2
    Last Post: 11-26-2008, 11:30 AM
  4. Replies: 3
    Last Post: 02-22-2008, 08:05 AM
  5. Number of files and directories in folder
    By dirkfirst in forum PHP Forum
    Replies: 4
    Last Post: 05-30-2006, 07:06 AM