Page 1 of 1

File dates and attributes

Posted: Tue Mar 16, 2004 8:58 pm
by Dreglor
i want to know how to get the date (modified only)
and any attibutes the file had
and is it possible to set these?

Posted: Tue Mar 16, 2004 9:27 pm
by AlGonzalez
For date information, look into the "GetFileTime_" and "FileTimeToSystemTime" Windows API calls.

Get/Set Attributes:

Code: Select all

Procedure.s ShowFileAttributes(file.s)
    Protected result.l, attribs.s
    
    result = GetFileAttributes_(file)

    attribs.s = ""
    If result & #FILE_ATTRIBUTE_DIRECTORY 
        attribs + "D"
    EndIf
    If result & #FILE_ATTRIBUTE_COMPRESSED 
        attribs + "C"
    EndIf
    If result & #FILE_ATTRIBUTE_READONLY 
        attribs + "R"
    EndIf
    If result & #FILE_ATTRIBUTE_ARCHIVE 
        attribs + "A"
    EndIf
    If result & #FILE_ATTRIBUTE_SYSTEM
        attribs + "S"
    EndIf
    If result & #FILE_ATTRIBUTE_HIDDEN 
        attribs + "H"
    EndIf
    
    ProcedureReturn attribs
EndProcedure

fn.s = "C:\selects.txt"
Debug ShowFileAttributes(fn)  ; result A
SetFileAttributes_(fn, #FILE_ATTRIBUTE_READONLY | #FILE_ATTRIBUTE_ARCHIVE | #FILE_ATTRIBUTE_SYSTEM | #FILE_ATTRIBUTE_HIDDEN)
Debug ShowFileAttributes(fn)  ; result RASH
SetFileAttributes_(fn, #FILE_ATTRIBUTE_ARCHIVE)
Debug ShowFileAttributes(fn)  ; result A
You may also want to look at the "DirectoryEntryAttributes" command.

HTH