If your query is just to use the Win API, read no further. If you just want to read file attributes with VBA, Dir works, as per the HELP system:
Dir Function
Returns a String representing the name of a file, directory, or folder that matches a specified pattern or file attribute, or the volume label of a drive.
Syntax
Dir[(pathname[, attributes])]
The Dir function syntax has these parts:
Part Description
pathname Optional. String expression that specifies a file name — may include directory or folder, and drive. A zero-length string ("" is returned if pathname is not found.
attributes Optional. Constant or numeric expression, whose sum specifies file attributes. If omitted, returns files that match pathname but have no attributes.
Settings
The attributes argument settings are:
Constant Value Description
vbNormal 0 (Default) Specifies files with no attributes.
vbReadOnly 1 Specifies read-only files in addition to files with no attributes.
vbHidden 2 Specifies hidden files in addition to files with no attributes.
VbSystem 4 Specifies system files in addition to files with no attributes. Not available on the Macintosh.
vbVolume 8 Specifies volume label; if any other attributed is specified, vbVolume is ignored. Not available on the Macintosh.
vbDirectory 16 Specifies directories or folders in addition to files with no attributes.
vbAlias 64 Specified file name is an alias. Available only on the Macintosh.
Note These constants are specified by Visual Basic for Applications and can be used anywhere in your code in place of the actual values.
Remarks
In Microsoft Windows, Dir supports the use of multiple character (*) and single character (?) wildcards to specify multiple files. On the Macintosh, these characters are treated as valid file name characters and can't be used as wildcards to specify multiple files.
MichaelRed
mred@att.net
There is never time to do it right but there is always time to do it over
Thank you for taking the time to provide that answer.
However, I believe the solution is through the Windows API. As I cannot seem to find any functions that will pull specific attributes from a folder. Unless you can tell me how to pull the following...
Folder Size
Folder Creation Date
Folder Last Modified Date
I already use DIR, but it only pulls the folder/file name. I thought about GetAttr function, but it only acquires flags on the folder.
Yes, I saw your response to another thread regarding the FileSystem object. I will research this further though initially I did not find what I was looking for exactly.
The DIR and/or attrib command will work fine. Just remember that if you are looking for directories/folders, you have to add the vbDirectory attribute. For example . . .
The example I gave was only used to show how to use the DIR command to read directories. By itself, it will not list dates. To get the folder creation or last modified date, use the FileDateTime command (i.e. MsgBox FileDateTime("C:\winnt"). To find the size of the folder, you need to iterate through the folder and add up each file. To get multiple files deep, you need to use a recursive call. If you want an example, let me know and I will post one tonight. - Jeff Marler B-)
Jmarler: Yes, thank you for your input and that was what I was afraid of. Strongm's solution seems ideal for Acces 2000 and above, but I could not use it for Acces97.
Urm...Access 97. I guess the problem is that you can't add the reference (it's been a while since I used Access 97)? But that's OK, since Access 97 does support the CreateObject method - so we can just rewrite the routine slightly:
Dim fso As Object
Dim myFolder As Object
Set fso = CreateObject("scripting.filesystemobject"
Set myFolder = fso.GetFolder("C:\temp"
With myFolder
Debug.Print .Size
Debug.Print .DateCreated
Debug.Print .DateLastModified
End With
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.