Dir(strPath, +R +A +S +H) keeps returning hidden folders

  • Thread starter Christian Blackburn
  • Start date
C

Christian Blackburn

Hi Gang,
All I want is to be able to search a file for files matching a certain
criteria. However, VB seems heart set on returning hidden folders
along with my list of files. I've tried the following:
strFile = Dir(strPath, FileAttribute.Archive Or FileAttribute.Hidden Or
FileAttribute.ReadOnly Or FileAttribute.System)

and this which shouldn't be necessary

strFile = Dir(strPath, FileAttribute.Archive Or FileAttribute.Hidden Or
FileAttribute.ReadOnly Or FileAttribute.System AND
FileAttribute.Directory)

Either way I still turn up my hidden ".svn" subfolder. (The folder is
hidden only, that is it's the only attribute, it's not system or
anything else).

I realize I could then do System.IO.File.Exists(strPath) to make sure
it's actually a file, but that would double the disk access. Pretty
lame if you ask me :).

Thanks for any and all help regarding this matter,
Christian Blackburn
 
K

Ken Tucker [MVP]

Hi,

Why not use the system.io.directoryinfo class to get the files. You
can specify a search pattern for the files.

Dim fi As System.IO.FileInfo
Dim di As New
System.IO.DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments))
For Each fi In di.GetFiles("*.ppt")
Trace.WriteLine(fi.Name)
Next

Ken
 
C

Christian Blackburn

Hi Ken,

That's just too easy, you make me sick :). No just kidding that's
great. I was trying for good performance though. However, I like the
code and think I will use it in my search application, since in that I
would be interested in all those file properties. Oh and I can also
use it in my indexing page
http://www.christianblackburn.com/misc/default.asp (obviously, I still
need to convert this to ASP 2.0). Thanks for your help, you probably
don't remember me, but I know you've helped me on a number of
occasions. Possibly even in the VB6 group :).

Cheers,
Christian Blackburn
 
C

Christian Blackburn

Hi Ken,

That's just too easy, you make me sick :). No just kidding that's
great. I was trying for good performance though. However, I like the
code and think I will use it in my search application, since in that I
would be interested in all those file properties. Oh and I can also
use it in my indexing page
http://www.christianblackburn.com/misc/default.asp (obviously, I still
need to convert this to ASP 2.0). Thanks for your help, you probably
don't remember me, but I know you've helped me on a number of
occasions. Possibly even in the VB6 group :). That's doen't look
recursive though, which is fine I can do recursion.

Cheers,
Christian Blackburn
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top