Discussion Locked

How can I get a file's attributes?

0 helpful
9 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Before running a program I want to check a few things about a file that the program will be using, things like when was it created and how big is it. I'm writing in Visual Basic 6. I'm new to VB, having moved from a mainframe environment. I know on the mainframe this kind of information is easy to get.

Any help would be appreciated.

9 replies

by peace monger

If you are looking for a programmatic way, I'm not sure. If you can get to a command prompt, then MS-DOS can tell you with

ATTRIB filespec
where filespec is the file name or expression (wildcards allowed).

The flags are R for readonly, H for hidden, S for system, and A for archive. Use DIR filespec to get filename, last modified date, and size in bytes.

by sl-campbell

If you are starting the program from a VB program then you can check the file properties of the files that that prg will use by using API calls, or by using the FileSystemObject:

Under Project|References select the 'Microsoft Scripting Runtime'
Then, in code:

Dim fso As FileSystemObject
Dim f As File
Set f = fso.GetFile("MyPath\MyFile")

then you can check certain properties like:

f.Attributes
f.DateCreated
f.DateLastAccessed
f.DateLastModified
f.ShortName
f.Type
f.Size

This discussion is closed to new replies.