PB調用API函數來尋找檔案

來源:互聯網
上載者:User

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

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.