Click here to Skip to main content
16,015,973 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Greetings.
I haven't used VB in several years, so this is like learning from scratch again.
I'm fiddling around with: My.Computer.FileSystem.GetFiles procedure, it works well except when I select a path including system folders like the Recycle Bin or Application Data.

The exception happens when the GetFiles procedure is called, in the old days I would have tested the attributes of each file after finding it on disk. I would think that there would be an option to exclude System or hidden files.


Here is a very, very simple example:
VB
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
   For Each foundFile As String In My.Computer.FileSystem.GetFiles _
      (txtDIR.Text, _
       FileIO.SearchOption.SearchAllSubDirectories, "*")

         Dim attributes As FileAttributes
         attributes = File.GetAttributes(foundFile)
        
         List2.Items.Add(IO.Path.GetFileName(foundFile))
    
   Next

End Sub
Posted
Updated 2-Apr-14 12:09pm
v2

Yes, there is an option to exclude system r hidden files. Use if ... then[^] statement inside for each loop.

VB
Dim attributes = File.GetAttributes(foundFile)
        If ((attributes And FileAttributes.ReadOnly) <> FileAttributes.ReadOnly) Then
            'add to list


For further information please see:
Walkthrough: Manipulating Files and Directories in Visual Basic[^]
How to: Enumerate Directories and Files[^]
FileAttributes Enumeration[^]
 
Share this answer
 
First of all, I would not recommend anything VB.NET-related. Why not using pure .NET BCL: http://msdn.microsoft.com/en-us/library/ms143316%28v=vs.110%29.aspx[^]?

However, you won't get anything new. Those types and methods clearly show… that you cannot ignore some particular directory from the search. You will need to find all files and then ignore some of the found ones, in further processing.

—SA
 
Share this answer
 
Thanks very much, its been a loooong time since I used VB, it's 100% different now.
 
Share this answer
 
Comments
Nelek 2-Apr-14 18:11pm    
Please don't post solutions to chat with people who answered, you get it better (and they get a notification) if you use the "have question or comment?" after each message (or the tiny "reply" in another comment)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900