Get file-creation date

Get file-creation date

Postby Marc Vanzegbroeck » Sat Mar 24, 2007 2:15 pm

Hi,

With directory() you can get dat date when the file is modified.
Is there a way to get the date of creation?
If you have a digital photograph, and rotate it, the date is changed.
In the exporer, the date of the file is changed, but not the date of creation of the file.

Thanks,
Marc
Marc Vanzegbroeck
 
Posts: 1159
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium

Re: Get file-creation date

Postby Enrico Maria Giordano » Sat Mar 24, 2007 7:01 pm

Code: Select all  Expand view
#include "Fivewin.ch"
#include "Directry.ch"


FUNCTION MAIN()

    LOCAL aDir := LFNDIRECTORY( "E:\*.*", "D" )

    LOCAL aNam := {}

    LOCAL i

    FOR i = 1 TO LEN( aDir )
        AADD( aNam, aDir[ i, F_NAME ] + CHR( 9 ) + LTRIM( STR( aDir[ i, F_SIZE ] ) ) + CHR( 9 ) + DTOC( aDir[ i, F_DATE ] ) + CHR( 9 ) + aDir[ i, F_TIME ] + CHR( 9 ) + aDir[ i, F_ATTR ] )
    NEXT

    WQOUT( aNam )

    RETURN NIL


// File attributes

#define FILE_ATTRIBUTE_READONLY  1
#define FILE_ATTRIBUTE_HIDDEN    2
#define FILE_ATTRIBUTE_SYSTEM    4
#define FILE_ATTRIBUTE_DIRECTORY 16
#define FILE_ATTRIBUTE_ARCHIVE   32
#define FILE_ATTRIBUTE_NORMAL    128
#define FILE_ATTRIBUTE_TEMPORARY 256


#include "Struct.ch"


#define MAX_PATH 260

#define ZTRIM( cString ) Left( cString, At( Chr( 0 ), cString ) - 1 )


FUNCTION LFNDIRECTORY( cFileSpec, cAttrib )

    LOCAL oWin32FindData := OWIN32FINDDATA()

    LOCAL cBuffer

    LOCAL hFile

    LOCAL aDir := {}

    LOCAL cName, nSize, dDate, cTime, cAttr

    DEFAULT cFileSpec := "*.*"
    DEFAULT cAttrib   := ""

    cBuffer = oWin32FindData:cBuffer

    hFile = FINDFIRSTFILE( cFileSpec, @cBuffer )

    oWin32FindData:cBuffer = cBuffer

    IF hFile = -1; RETURN {}; ENDIF

    WHILE .T.
        DO CASE
            CASE !( "D" $ cAttrib ) .AND. NAND( oWin32FindData:nFileAttr, FILE_ATTRIBUTE_DIRECTORY ) != 0
            CASE !( "H" $ cAttrib ) .AND. NAND( oWin32FindData:nFileAttr, FILE_ATTRIBUTE_HIDDEN ) != 0
            CASE !( "S" $ cAttrib ) .AND. NAND( oWin32FindData:nFileAttr, FILE_ATTRIBUTE_SYSTEM ) != 0
            OTHERWISE
                cName = ZTRIM( oWin32FindData:cFileName )
                nSize = 4294967296 * oWin32FindData:nFileSizeH + oWin32FindData:nFileSizeL
//                dDate = FILEDATE( oWin32FindData:cLastWTime )
//                cTime = FILETIME( oWin32FindData:cLastWTime )
                dDate = FILEDATE( oWin32FindData:cCreatTime )
                cTime = FILETIME( oWin32FindData:cCreatTime )
                cAttr = FILEATTR( oWin32FindData:nFileAttr )

                AADD( aDir, { cName, nSize, dDate, cTime, cAttr } )
        ENDCASE

        cBuffer = oWin32FindData:cBuffer

        IF !FINDNEXTFILE( hFile, @cBuffer ); EXIT; ENDIF

        oWin32FindData:cBuffer = cBuffer
    ENDDO

    FINDCLOSE( hFile )

    RETURN aDir


FUNCTION FILEDATE( cFileDtTm )

    LOCAL oLocalFileTime := OFILETIME()
    LOCAL oSystemTime    := OSYSTEMTIME()

    LOCAL cBuffer

    oLocalFileTime:cBuffer = cFileDtTm

    cBuffer = oLocalFileTime:cBuffer

    FTTOLOCALFT( cFileDtTm, @cBuffer )

    oLocalFileTime:cBuffer = cBuffer

    cBuffer = oSystemTime:cBuffer

    FTTOSYSTIME( oLocalFileTime:cBuffer, @cBuffer )

    oSystemTime:cBuffer = cBuffer

    RETURN STOD( STR( oSystemTime:nYear, 4 ) + STRZERO( oSystemTime:nMonth, 2 ) + STRZERO( oSystemTime:nDay, 2 ) )


FUNCTION FILETIME( cFileDtTm )

    LOCAL oLocalFileTime := OFILETIME()
    LOCAL oSystemTime    := OSYSTEMTIME()

    LOCAL cBuffer

    oLocalFileTime:cBuffer = cFileDtTm

    cBuffer = oLocalFileTime:cBuffer

    FTTOLOCALFT( cFileDtTm, @cBuffer )

    oLocalFileTime:cBuffer = cBuffer

    cBuffer = oSystemTime:cBuffer

    FTTOSYSTIME( oLocalFileTime:cBuffer, @cBuffer )

    oSystemTime:cBuffer = cBuffer

    RETURN STRZERO( oSystemTime:nHour, 2 ) + ":" + STRZERO( oSystemTime:nMinute, 2 ) + ":" + STRZERO( oSystemTime:nSecond, 2 )


FUNCTION FILEATTR( nAttrib )

    LOCAL cAttrib := ""

    IF NAND( nAttrib, FILE_ATTRIBUTE_ARCHIVE ) != 0; cAttrib += "A"; ENDIF
    IF NAND( nAttrib, FILE_ATTRIBUTE_DIRECTORY ) != 0; cAttrib += "D"; ENDIF
    IF NAND( nAttrib, FILE_ATTRIBUTE_HIDDEN ) != 0; cAttrib += "H"; ENDIF
    IF NAND( nAttrib, FILE_ATTRIBUTE_READONLY ) != 0; cAttrib += "R"; ENDIF
    IF NAND( nAttrib, FILE_ATTRIBUTE_SYSTEM ) != 0; cAttrib += "S"; ENDIF

    RETURN cAttrib


FUNCTION OFILETIME()

    LOCAL oFileTime

    STRUCT oFileTime
        MEMBER nLDateTime AS DWORD
        MEMBER nHDateTime AS DWORD
    ENDSTRUCT

    RETURN oFileTime


FUNCTION OSYSTEMTIME()

    LOCAL oSystemTime

    STRUCT oSystemTime
        MEMBER nYear      AS WORD
        MEMBER nMonth     AS WORD
        MEMBER nDayOfWeek AS WORD
        MEMBER nDay       AS WORD
        MEMBER nHour      AS WORD
        MEMBER nMinute    AS WORD
        MEMBER nSecond    AS WORD
        MEMBER nMilliSecs AS WORD
    ENDSTRUCT

    RETURN oSystemTime


FUNCTION OWIN32FINDDATA()

    LOCAL oWin32FindData

    STRUCT oWin32FindData
        MEMBER nFileAttr  AS DWORD
        MEMBER cCreatTime AS STRING LEN 8
        MEMBER cLastATime AS STRING LEN 8
        MEMBER cLastWTime AS STRING LEN 8
        MEMBER nFileSizeH AS DWORD
        MEMBER nFileSizeL AS DWORD
        MEMBER nReserved0 AS DWORD
        MEMBER nReserved1 AS DWORD
        MEMBER cFileName  AS STRING LEN MAX_PATH
        MEMBER cShortName AS STRING LEN 14
    ENDSTRUCT

    RETURN oWin32FindData


DLL32 FUNCTION FTTOLOCALFT( cFileTime AS LPSTR, @cLocalFileTime AS LPSTR ) AS BOOL;
      PASCAL FROM "FileTimeToLocalFileTime" LIB "kernel32.dll"

DLL32 FUNCTION FTTOSYSTIME( cFileTime AS LPSTR, @cSystemTime AS LPSTR ) AS BOOL;
      PASCAL FROM "FileTimeToSystemTime" LIB "kernel32.dll"

DLL32 FUNCTION FINDCLOSE( nFindFile AS LONG ) AS BOOL;
      PASCAL FROM "FindClose" LIB "kernel32.dll"

DLL32 FUNCTION FINDFIRSTFILE( cFileName AS LPSTR, @cFindFileData AS LPSTR ) AS LONG;
      PASCAL FROM "FindFirstFileA" LIB "kernel32.dll"

DLL32 FUNCTION FINDNEXTFILE( nFindFile AS LONG, @cFindFileData AS LPSTR ) AS BOOL;
      PASCAL FROM "FindNextFileA" LIB "kernel32.dll"


EMG
User avatar
Enrico Maria Giordano
 
Posts: 8712
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby Marc Vanzegbroeck » Sun Mar 25, 2007 9:56 pm

Thanks Enrico, I will try it.

Marc
Marc Vanzegbroeck
 
Posts: 1159
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium


Return to FiveWin for CA-Clipper

Who is online

Users browsing this forum: No registered users and 5 guests