PB calls API functions to find files

Source: Internet
Author: User
Tags filetime

Http://blog.csdn.net/eastlife2008/article/details/2049983

PB Syntax:

Struct definition:

Global Type win32_find_data from Structure
Unsignedlong dwfileattributes
Unsignedlong ftcreationtime
Unsignedlong ftlastaccesstime
Unsignedlong ftlastwritetime
Unsignedlong nfilesizehigh
Unsignedlong nfilesizelow
Unsignedlong dwreserved0
Unsignedlong dwreserved1
Character cfilename [260]
Character calternatefilename [14]
End type

Global Type ofstruct from Structure
Unsignedinteger cbytes
Unsignedinteger ffixeddisk
Integer nerrcode
Integer reserved1
Integer reserved2
Character szpathname [1, 128]
End type

Global Type filetime from Structure
Long dwlowdatetime
Long dwhighdatetime
End type

Global Type systemtime from Structure
Integer wyear
Integer wmonth
Integer wdayofweek
Integer wday
Integer whour
Integer wminute
Integer wsecond
Integer wmilliseconds
End type

The function is defined as follows:

// Query the date and time of the file
Function ulong closehandle (ulong hobject) Library "kernel32.dll" alias for "closehandle; ANSI"

Function ulong openfile (ref string lpfilename, ref ofstruct lpreopenbuff, ulong wstyle) Library "kernel32.dll" alias for "openfile; ANSI"
Function ulong filetimetosystemtime (ref filetime lpfiletime, ref systemtime lpsystemtime) Library "kernel32.dll" alias for "filetimetosystemtime; ANSI"
Function ulong getfiletime (ulong hfile, ref filetime lpcreationtime, ref filetime lplastaccesstime, ref filetime lplastwritetime) Library "kernel32.dll" alias for "getfiletime; ANSI"
// Search for files
Function long findfirstfile (string lpfilename, ref win32_find_data lpfindfiledata) Library "Kernel32" alias for "findfirstfilea; ANSI"

Function long findnextfile (long hfindfile, ref win32_find_data lpfindfiledata) Library "Kernel32" alias for "findnextfilea; ANSI"
Function long findclose (long hfindfile) Library "Kernel32" alias for "findclose; ANSI"
Function long getlasterror () Library "Kernel32" alias for "getlasterror; ANSI"

Code Section (search for files ):

Win32_find_data FinDATA

Ofstruct lst_ofstruct
Filetime lst_filetime1, lst_filetime2, lst_filetime3
Systemtime sys1

Ll_ret = findfirstfile (ls_drieve, FinDATA)
If ll_ret <>-1 then
B _hadfile = true
// Obtain the file size
Ll_filesize = filelength (ls_findfn)
// Obtain the file modification time
Lul_hfile = openfile (ls_findfn, lst_ofstruct, 0)
Getfiletime (lul_hfile, lst_filetime1, lst_filetime2, lst_filetime3)
Filetimetosystemtime (lst_filetime3, sys1)
Closehandle (lul_hfile)
Dt_fileeditdt = datetime (string (sys1.wyear) + "-" + String (sys1.wmonth) + "-" + String (sys1.wday) + &

"" + String (sys1.whour) + ":" + String (sys1.wminute) + ":" + String (sys1.wsecond ))

Dt_fileeditdt = datetime (date (dt_fileeditdt), time (relativetime (Time (dt_fileeditdt), 28800 )))

Do While findnextfile (ll_ret, FinDATA) <> 0
// Obtain the file size
Ll_filesize = filelength (ls_findfn)
// Obtain the file modification time
Lul_hfile = openfile (ls_findfn, lst_ofstruct, 0)
Getfiletime (lul_hfile, lst_filetime1, lst_filetime2, lst_filetime3)
Filetimetosystemtime (lst_filetime3, sys1)
Closehandle (lul_hfile)
Dt_fileeditdt = datetime (string (sys1.wyear) + "-" + String (sys1.wmonth) + "-" + String (sys1.wday) + &

"" + String (sys1.whour) + ":" + String (sys1.wminute) + ":" + String (sys1.wsecond ))

Dt_fileeditdt = datetime (date (dt_fileeditdt), time (relativetime (Time (dt_fileeditdt), 28800 )))
Loop
// Close the file search
Findclose (ll_ret)
Else
B _hadfile = false
End if

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.