CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    May 2002
    Posts
    78

    How do I get certain file properties?

    Hi,
    How do I get certain properties of a file and set them to variables, as in the porperties that you get when you right click on a file and select properties.

    I want to be able to set the variables:
    m_LastMod to the Modified: dd/mm/yy, time, bit of the file properties

    m_CreationDate to the Created: dd/mm/yy time bit of the file properties

    and
    m_FileSize to the SIze: xxxMB(xxxxxxxbytes) bit of the file properties


    I don't mind whether I have just the numbers or the whole thing.

    The problem is I just don't know how to do it, I tried searching the VC++ help but I could only find things for other languages and on how to see the file properties in the VC++ application. My books that I have don't cover anything on this topic either.

    I hope someone can help
    Cheers
    CJN

  2. #2
    Join Date
    Apr 2002
    Location
    Boston, MA
    Posts
    40
    Hi CJN,

    Check out CFileStatus.

    If you have a file opened as a CFile you can call the GetStatus method on it which will give you all this information!

    Hope this works

  3. #3
    Join Date
    May 2002
    Posts
    78
    hi,

    Thanks for trying to help but it doesn't really help. I don't see how I can make use of this GETSTATUS to get the file's size, creation and modification date.

    The pathname of the file is stored in a variable called m_Location and I would like to get the properties I said about using this pathname.

    Please can you or anyone give any further help?

    Cheers
    CJN

  4. #4
    Join Date
    Apr 2002
    Location
    Boston, MA
    Posts
    40
    I guess you are looking for specific code then:

    --- begin code
    // m_Location is the path to the file:
    CFileStatus oStatus
    CFile::GetStatus(m_Location, oStatus);

    CTime oCreationTime = oStaus.m_ctime;
    CTime oModifiedTime = oStatus.m_mtime;
    CTime oLastAccessedTime = oStatus.m_atime;
    LONG nFileSize = oStatus.m_size;

    --- end code

    You can use CTime's Format() method to get the date as mm/dd/yyyy or whatever you wish.

    To change any of the file's properties use CFile's SetStatus as in:

    CFile::SetStatus(m_Location, oStatus);

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured