PB调用API函数来查找文件

PB语法:

结构体定义:

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[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

函数定义如下: 

//查找文件的日期时间
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"
//查找文件
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"

代码部分(查找文件):

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    
    //得出文件大小
    ll_filesize = FileLength(ls_findFN)
    //得出文件的修改时间
    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
     //得出文件大小
     ll_filesize = FileLength(ls_findFN) 
     //得出文件的修改时间
     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 
    //关闭查找文件
    FindClose(ll_ret)  
   else
    b_hadfile = false
   end if

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值