×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Directory Traversal Errata

Directory Traversal Errata

Directory Traversal Errata

(OP)
I have spent a few days researching directory traversing in VB 6.0.  I have found that most use this kind of approach:

1:  File_Name = Dir$(File_Path, vbDirectory)
2:  Do While File_Name <> ""
3:      File_Name = Dir$
4:  Loop


It is then used in a recursive manner.

What I have found frustrating is that all the examples I find, don't work?  

I think line 1 of the code above should return a pointer to a list of directory names?  But instead it returns all items in the directory?  What is the point of specifying vbDirectory?

Once I realized that everything is brought back (dir, files), I found that someone used this function to determine the type of item:

GetAttr(File_Path & File_Name) = X

Where X is a code for a type of attribute for a file.  
In all the examples I found, all used vbDirectory as X (16).
I understand what is done here, but in testing I found the following to be valid values for directories (X):

8240
8241
8208

Am I in the correct thinking, or is there a better way?  Also, if I am correct about this being the best way to do things:

1:  File_Name = Dir$(File_Path, vbDirectory)
2:  Do While File_Name <> ""
3:    If GetAttr(File_Path & File_Name) = 8240 Or GetAttr(File_Path & File_Name) = 8241 Or GetAttr(File_Path & File_Name) = 8208 Then
4:      ' Is Directory call function again
5:    Else
6:      ' Is File
7:    end if
8:      File_Name = Dir$
4:  Loop


where can I find a lising of return values for getattr() function, and does this list change from OS to OS?

RE: Directory Traversal Errata

bont,

Consider FileSystemObject (FSO) Class instead. It is very flexible and easy to use.

Vladk

RE: Directory Traversal Errata

For getattr() function values see:

http://support.microsoft.com/default.aspx?scid=http://s...

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'

RE: Directory Traversal Errata

(OP)
OK, correct me if I am wrong. I am judging that this thread to microsoft is what would be needed to use this windows API technique.  In the course of doing so the vb constants, i.e. vbDirectory should work properly.  My way is much simpler, but I don't know if I can trust the attributes function (the thread doesn't list them, if someone knows of a list, please help).  I would suspect these can change from OS to OS?  Anyway, after looking at the filesystem obj, this might be the easiest to implement.  The same recursive theory, but less need for detail.  Much more reliable if the object crosses the OS boundaries without problems.

RE: Directory Traversal Errata

bont,

FSO is recommended in both VB6 and .NET to perform common file system tasks. That is, it should be good for all Windows platforms including XP. That object is essentially a wrapper around API calls.

Vladk

RE: Directory Traversal Errata

In the reference I gave, about 10 lines down in the first example code you will find:

Public Const FILE_ATTRIBUTE_ARCHIVE = &H20
   Public Const FILE_ATTRIBUTE_DIRECTORY = &H10
   Public Const FILE_ATTRIBUTE_HIDDEN = &H2
   Public Const FILE_ATTRIBUTE_NORMAL = &H80
   Public Const FILE_ATTRIBUTE_READONLY = &H1
   Public Const FILE_ATTRIBUTE_SYSTEM = &H4
   Public Const FILE_ATTRIBUTE_TEMPORARY = &H100

These remain (AFAIK) consistent for all modern operating systems.

Alternatively you can use the Object Browser and do a search for vbFileAttribute, where the VB intrinsic constants are all listed.

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'

RE: Directory Traversal Errata

(OP)
I still don't agree with this windows API methos.  When I use vbDirectory, it returns everything, directories and files.  So I guress my vbDirectory is not set correctly.  To combat this I use getatt() function, and I find that a directory can be any of 3 different values, adn this function apparently returns codes for different types of directories, but appears to be consistent.  FileSystemObject is more consistent, with less code.  Thanks for the help all.

RE: Directory Traversal Errata

If you use:

 If GetAttr(File_Path & File_Name) AND vbDirectory = vbDirectory

which only picks up the Dir attribute it will be accurate

Each value is a one-bit value in a Long integer, so the values you see with GetAttr on it's own is the Integer value. Doing a logical AND with the appropriate vb constant will produce your correct answer directly

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close