PDA

View Full Version : kernel32 GetFileAttributes Directory type Help



gatonegro75
12-18-2008, 10:36 AM
Hi,

I've trawled the internet with little success.

I have a bit of vba which will drill down through sub directories, and I use the code below to check to see which files are directories: -


Private Declare Function GetFileAttributes Lib "kernel32" Alias "GetFileAttributesA" (ByVal lpFileName As String) As Long

MsgBox GetFileAttributes(strStartFolderPath)

A normal directory returns an integer value of 16. Though some directories will return a value of 48 or 50, depending on whether a directory is read only etc

I'm looking to find a complete list of possible directory values. Anyone have any ideas?

Thanks Tom

Kenneth Hobs
12-18-2008, 10:48 AM
What is the goal, to get the attributes for a folder and its subfolders?

gatonegro75
12-18-2008, 11:00 AM
I want to get a complete view of all directories. When I was going through my code I noticed that not all directories were getting picked up.

I noted that normal directories have a value of 16 but some of the directories have a value of 48 or 50. So I'm trying to make my code as robust as possible in case the end user has any other types of directory.

As well as the command button browse for directory help you provide yesterday. I tied that in with a test box so that the user can edit paths in there. So I also want to validate any manual edited path string.

Thanks

Kenneth Hobs
12-18-2008, 12:05 PM
What does complete view of all directories mean?

I created functions to return an array of filenames that match a wildcard search and subfolders if set. The methods vary because Excel 2007 eliminated FileSearch. Most use a File System Object approach. Once one knows the filenames, one can add it to a sheet or whatever. If this interests you see: http://www.vbaexpress.com/forum/showthread.php?t=22245


Keep in mind that attributes are packed so the value returned will need to be parsed. See the help for GetAttr() for details.

Paul_Hossler
12-18-2008, 06:51 PM
The file attributes are bit mapped, and seveal bits can be set. Look in Help for GetAttr:

Return Values
The value returned by GetAttr is the sum of the following attribute values:
Constant Value Description
vbNormal 0 Normal.
vbReadOnly 1 Read-only.
vbHidden 2 Hidden.
vbSystem 4 System file. Not available on the Macintosh.
vbDirectory 16 Directory or folder.
vbArchive 32 File has changed since last backup. Not available on the Macintosh.
vbAlias 64 Specified file name is an alias. Available only on the Macintosh

So a Hidden, System Directory would have 2 + 4 + 16 = 22

As I recall 8 is the System Volume entry in the file table

So something like

If AND (ATTR,16) = 16 then it's a directory

would find them all

Paul