본문 바로가기
프로그래밍/PowerBuilder

파워빌더에서 파일 날짜 알아오기

by MAKING_ 2020. 10. 31.
반응형

다음은 파일의 날짜를 구하는 of_getdatetime함수입니다.



사용하실때는

string file_name, client_date

file_name = "c:연습연습.exe"

client_date = of_getdatetime(file_name)

하시면 되겠지요^^



1. Declare -> Global External Function 선언

Function boolean GetFileTime(ulong hFile, ref os_filedatetime lpCreationTime, ref os_filedatetime lpLastAccessTime, ref os_filedatetime lpLastWriteTime ) library "KERNEL32.DLL"

Function ulong OpenFile (ref string filename, ref os_fileopeninfo of_struct, ulong action) LIBRARY "KERNEL32.DLL"

Function boolean CloseHandle (ulong file_hand) LIBRARY "KERNEL32.DLL"

Function boolean FileTimeToSystemTime(ref os_filedatetime lpFileTime, ref os_systemtime lpSystemTime) library "KERNEL32.DLL"

Function boolean FileTimeToLocalFileTime(ref os_filedatetime lpFileTime, ref os_filedatetime lpLocalFileTime) library "KERNEL32.DLL"



2. 구조체 작성

os_filedatetime

ul_lowdatetime unsignedlong

ul_hightdatetime unsignedlong



os_fileopeninfo

c_length character

c_fixed_disk character

ui_dos_error unsignedinteger

ui_na1 unsignedinteger

ui_na2 unsignedinteger

c_pathname[128] character



os_systemtime

ui_wyear unsignedinteger

ui_wmonth unsignedinteger

ui_wdayofweek unsignedinteger

ui_wday unsignedinteger

ui_whour unsignedinteger

ui_wminute unsignedinteger

ui_wsecond unsignedinteger

ui_wmilliseconds unsignedinteger



3. 함수 작성(of_getdatetime())

// return string

// arg as_filename string

string ls_Time, server_date, client_date, server_time, client_time

date ad_FileDate

time at_FileTime

boolean lb_Ret

ulong lul_Handle



os_filedatetime lstr_LocalTime

os_systemtime lstr_SystemTime

os_filedatetime astr_filetime



os_fileopeninfo lstr_FileInfo

os_filedatetime lpCreationTime, lpLastAccessTime, lpLastWriteTime



// Set the file structure information

lstr_FileInfo.c_fixed_disk = "~000"

lstr_FileInfo.c_pathname = as_FileName

lstr_FileInfo.c_length = "~142"



// Open the file

lul_Handle = OpenFile ( as_FileName, lstr_FileInfo, 2 )

lb_Ret = GetFileTime( lul_Handle, lpCreationTime, lpLastAccessTime, lpLastWriteTime )

CloseHandle(lul_Handle)



If not lb_Ret Then

return("00-00-00,00:00:00")

End If



FileTimeToLocalFileTime(lpLastWriteTime, lstr_LocalTime)

FileTimeToSystemTime(lstr_LocalTime, lstr_SystemTime)



// works with all date formats

ad_FileDate = Date(lstr_SystemTime.ui_wyear, lstr_SystemTime.ui_WMonth, lstr_SystemTime.ui_WDay)



ls_Time = String(lstr_SystemTime.ui_wHour) + ":" + &

String(lstr_SystemTime.ui_wMinute) + ":" + &

String(lstr_SystemTime.ui_wSecond) + ":" + &

String(lstr_SystemTime.ui_wMilliseconds)

at_FileTime = Time(ls_Time)



return (string(ad_FileDate) + "," + string(at_FileTime))



=================================================================

반응형

댓글