Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get the file info

Status
Not open for further replies.

kshea

Technical User
May 31, 2002
60
CA
Hi All:

I'm trying to get the file info, such as the file size, created and modified time. I know in VB, we can use file system object like the following:

' Get the date file was created
Set fs = CreateObject ("Scripting.FileSystemObject")
Set f = fs.GetFile (cDataFile)
LayDate = f.DateCreated
' Remove seconds from the time
LayDate = Left(LayDate, Len(LayDate) - 3)
LayDate = Replace(LayDate, " ", ",")

Set f = Nothing

Set fs = Nothing

But, does anyone know the equivalent code in visual c++?
Thank you in advance.

 
[tt]CFileStatus fs;

CFile::GetStatus("pathToFile",fs);

// all file info now in fs[/tt]

To see the members of CFileStatus, look it up on MSDN - it'll give you the create/modified/access times, file size in bytes plus all the attributes such as read-only, etc.
tellis.gif

programmer (prog'ram'er), n A hot-headed, anorak wearing, pimple-faced computer geek.
 
Yes, but that's only if you've included support for the MFC classes (which you might not want if it's only for the filestatus). I can't remember exactly which API's I used, but if you do NOT want to include MFC support let me know and I will post them when I get home.
Greetings,
Rick
 
[tt]GetFileAttributes()[/tt] and [tt]GetFileSize()[/tt] are 2 API calls you could use if you're not using MFC - there's also the [tt]GetFileInformationByHandle()[/tt] API which includes the modified/access/create times.
tellis.gif

programmer (prog'ram'er), n A hot-headed, anorak wearing, pimple-faced computer geek.
 
Thank both of you. I'm not using MFC so I used GetFileSize(), GetFileTime() and GetFileAttributes() as you posted.

Thanks again for you help.
Kay

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top