DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 6 of 6

Thread: Skipping System Folders in search

  1. #1
    Join Date
    Jul 2010
    Location
    Florida
    Posts
    5

    Unhappy Skipping System Folders in search

    Hello,

    I have found some code here (DevX, it's fast, easy to understand and most of all, it works very well.) that searches thru all folders, subfolders and files given a starting point. Is there a way to avoid going down thru system folders (like windows) and $recycle.bin? Maybe there isn't a way but even that is a great answer.

    I'd "simply" like to say skip to the next folder at this level if the one I'm at is a system folder.

    A snippet of the code I use follows:
    Code:
    Private Sub SearchForFiles(sRoot As String)
    
    Dim WFD As WIN32_FIND_DATA
    Dim hFile As Long
       hFile = FindFirstFile(sRoot & ALL_FILES, WFD)
        If hFile <> INVALID_HANDLE_VALUE Then
           Do
              If (WFD.dwFileAttributes And vbDirectory) Then
                If Asc(WFD.cFileName) <> vbDot Then
                   If fp.bRecurse Then
                      SearchForFiles sRoot & TrimNull(WFD.cFileName) & vbBackslash
                   End If
                 End If
               Else
                  'must be a file..
                  If MatchSpec(WFD.cFileName, fp.sFileNameExt) Then
                      fp.nCount = fp.nCount + 1
                         handlefile fp.nCount - 1, sRoot, TrimNull(WFD.cFileName)
                   End If  'If MatchSpec
                End If 'If WFD.dwFileAttributes
               fp.nSearched = fp.nSearched + 1
           Loop While FindNextFile(hFile, WFD)
       End If 'If hFile
       Call FindClose(hFile)
    Last edited by Hack; 07-02-2010 at 07:37 AM. Reason: Added Code Tags

  2. #2
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,663
    Welcome to DevX

    I think you would have to individually list every folder you wanted to skip. You would need to play around with this, but I would image something like
    Code:
    Private Sub SearchForFiles(sRoot As String)
    
    Dim WFD As WIN32_FIND_DATA
    Dim hFile As Long
       hFile = FindFirstFile(sRoot & ALL_FILES, WFD)
        If hFile <> INVALID_HANDLE_VALUE Then
           Do
              If (WFD.dwFileAttributes And vbDirectory) Then
                If Asc(WFD.cFileName) <> vbDot Then
                   If Asc(WFD.cFileName) <> "c:\windows" _
                      Or Asc(WFD.cFileName) <> "c:\windows\system32" _
                      Or Asc(WFD.cFileName) <> "etc etc etc" Then
                   'rest of code
    Incidentially, I edited your first post and add [code]your code goes here[/code] tags as that makes reading posted code soooooo much easier.
    Last edited by Hack; 07-02-2010 at 07:43 AM.

  3. #3
    Join Date
    Jul 2010
    Location
    Florida
    Posts
    5

    Smile Skipping System Folders in search

    Thank you, Hack, for your quick response. So, I guess there's no attribute that determines a folder to be of "system" status. I'll plug in your suggestions and give it a try.


    Thank you again,
    Paul

  4. #4
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,663
    You can determine if a folder is a system folder using the FileSystemObject (FSO).

    However, as there are, typically, only going to be two system folders (\windows and \windows\system32) it doesn't seem worth the effort to include the FileSystemObject when you can simply exclude those two from your search.

    The other folders you originally mentioned are not system folders, but rather fall under the category of "Special Folders" which is a whole nuther ball game.

  5. #5
    Join Date
    Jun 2009
    Posts
    135
    Dir has a vbSystem constant one can use...



    Good Luck

  6. #6
    Join Date
    Jul 2010
    Location
    Florida
    Posts
    5
    Thanks everyone. I'd rather stay away from FSO. Your suggestions work just fine. The "special folders" I can handle. Have a great day.

Similar Threads

  1. Replies: 0
    Last Post: 07-25-2006, 11:34 PM
  2. Search System Tray
    By MyPlague in forum .NET
    Replies: 2
    Last Post: 03-20-2006, 06:18 PM
  3. Accessing System Folders
    By Jim Brooke in forum .NET
    Replies: 0
    Last Post: 08-11-2003, 01:17 PM
  4. Recursive search in public folders
    By Brecki in forum Enterprise
    Replies: 0
    Last Post: 03-07-2002, 10:39 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center