用户操作
[留言]  [发消息]  [加为好友] 
订阅我的博客
XML聚合    FeedSky
订阅到鲜果
订阅到Google
订阅到抓虾
eastlife2008的公告
文章分类
    存档

    原创  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

    发表于 @ 2008年01月17日 18:11:00 | 评论( loading... ) | 编辑| 举报| 收藏

    旧一篇:Delphi调用WinSock和API来取MAC地址 | 新一篇:求某个非常大的数的递加的结果,最佳算法

    • 发表评论
    • 评论内容:
    •  
    Copyright © eastlife2008
    Powered by CSDN Blog