Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how to use findfirstfile API?

272 views
Skip to first unread message

cherng32

unread,
Aug 21, 2015, 6:09:45 AM8/21/15
to
Dear all:
i'm use power builder 12 on win7 64bit,i want use findfirstfile API to get file modify date,but i can't get file date?

【first】: Structure
1.1 filetime
ulong dwLowDateTime
ulong dwHighDateTime
1.2 systemtime
uint wYear
uint wMonth
uint wDayOfWeek
uint wDay
uint wHour
uint wMinute
uint wSecond
uint wMilliseconds
1.3 WIN32_FIND_DATA
unsignedlong fileattributes
filetime creationtime
filetime lastaccesstime
filetime lastwritetime
unsignedlong filesizehigh
unsignedlong filesizelow
unsignedlong reserved0
unsignedlong reserved1
character filename[260]
character alternatefilename[14]

【Second】: External Functions
Function uLong FindFirstFile (String lpFileName , ref WIN32_FIND_DATA lpFindFileData) Library "kernel32.dll" Alias for "FindFirstFileA"
Function uLong FileTimeToSystemTime (FILETIME lpFileTime , ref SYSTEMTIME lpSystemTime) Library "kernel32" Alias for "FileTimeToSystemTime"

3.範例程式如下:
string ls_creationdate , ls_creationtime
string ls_lastaccessdate , ls_lastaccesstime
string ls_lastwritedate , ls_lastwritetime
string as_filename = 'c:\EMPLOYEE.DAT' // 檔案名稱
long ll_size = 0 // 檔案大小 Byte
datetime ldtm_creationtime // 檔案建立時間
datetime ldtm_lastaccesstime // 檔案最後存取時間
datetime ldtm_lastwritetime // 檔案最後寫入時間
win32_find_data lstr_find_data
systemtime lstr_systemtime
// 取得檔案大小
ll_FileNum = FindFirstFile(as_filename , lstr_find_data)
ll_size = lstr_find_data.filesizelow
// 取得檔案時間
if FindFirstFile(as_filename , lstr_find_data) > 0 then
FileTimeToSystemTime( lstr_find_data.creationtime , lstr_systemtime)
ls_creationdate = right('0000' + string( lstr_systemtime.wyear ) , 4) + '/' + right('00' + string( lstr_systemtime.wmonth ) , 2) + '/' + right('00' + string( lstr_systemtime.wday ) , 2)
ls_creationtime = right('00' + string( lstr_systemtime.whour ) , 2) + ':' + right('00' + string( lstr_systemtime.wminute ) , 2) + ':' + right('00' + string( lstr_systemtime.wsecond ) , 2)
FileTimeToSystemTime( lstr_find_data.lastaccesstime , lstr_systemtime)
ls_lastaccessdate = right('0000' + string( lstr_systemtime.wyear ) , 4) + '/' + right('00' + string( lstr_systemtime.wmonth ) , 2) + '/' + right('00' + string( lstr_systemtime.wday ) , 2)
ls_lastaccesstime = right('00' + string( lstr_systemtime.whour ) , 2) + ':' + right('00' + string( lstr_systemtime.wminute ) , 2) + ':' + right('00' + string( lstr_systemtime.wsecond ) , 2)
FileTimeToSystemTime( lstr_find_data.lastwritetime , lstr_systemtime)
ls_lastwritedate = right('0000' + string( lstr_systemtime.wyear ) , 4) + '/' + right('00' + string( lstr_systemtime.wmonth ) , 2) + '/' + right('00' + string( lstr_systemtime.wday ) , 2)
ls_lastwritetime = right('00' + string( lstr_systemtime.whour ) , 2) + ':' + right('00' + string( lstr_systemtime.wminute ) , 2) + ':' + right('00' + string( lstr_systemtime.wsecond ) , 2)
// 設定時間變數
ldtm_creationtime = datetime( date(ls_creationdate) , time(ls_creationtime) )
ldtm_lastaccesstime = datetime( date(ls_lastaccessdate) , time(ls_lastaccesstime) )
ldtm_lastwritetime = datetime( date(ls_lastwritedate) , time(ls_lastwritetime) )
end if

0 new messages