其实只需改一下参数 就可以了<br><br>用法差不多,你参考delphi封装好的三<br><br><br>function FindMatchingFile(var F: TSearchRec): Integer;<br>{$IFDEF MSWINDOWS}<br>var<br> LocalFileTime: TFileTime;<br>begin<br> with F do<br> begin<br> while FindData.dwFileAttributes and ExcludeAttr <> 0 do<br> if not FindNextFile(FindHandle, FindData) then<br> begin<br> Result := GetLastError;<br> Exit;<br> end;<br> FileTimeToLocalFileTime(FindData.ftLastWriteTime, LocalFileTime);<br> FileTimeToDosDateTime(LocalFileTime, LongRec(Time).Hi,<br> LongRec(Time).Lo);<br> Size := FindData.nFileSizeLow;<br> Attr := FindData.dwFileAttributes;<br> Name := FindData.cFileName;<br> end;<br> Result := 0;<br>end;<br>{$ENDIF}<br>{$IFDEF LINUX}<br>var<br> PtrDirEnt: PDirEnt;<br> Scratch: TDirEnt;<br> StatBuf: TStatBuf;<br> LinkStatBuf: TStatBuf;<br> FName: string;<br> Attr: Integer;<br> Mode: mode_t;<br>begin<br> Result := -1;<br> PtrDirEnt := nil;<br> if readdir_r(F.FindHandle, @Scratch, PtrDirEnt) <> 0 then<br> Exit;<br> while PtrDirEnt <> nil do<br> begin<br> if fnmatch(PChar(F.Pattern), PtrDirEnt.d_name, 0) = 0 then<br> begin // F.PathOnly must include trailing backslash<br> FName := F.PathOnly + string(PtrDirEnt.d_name);<br><br> if lstat(PChar(FName), StatBuf) = 0 then<br> begin<br> Attr := 0;<br> Mode := StatBuf.st_mode;<br><br> if S_ISDIR(Mode) then<br> Attr := Attr or faDirectory<br> else<br> if not S_ISREG(Mode) then // directories shouldn't be treated as system files<br> begin<br> if S_ISLNK(Mode) then<br> begin<br> Attr := Attr or faSymLink;<br> if (stat(PChar(FName), LinkStatBuf) = 0) and<br> S_ISDIR(LinkStatBuf.st_mode) then<br> Attr := Attr or faDirectory<br> end;<br> Attr := Attr or faSysFile;<br> end;<br><br> if (PtrDirEnt.d_name[0] = '.') and (PtrDirEnt.d_name[1] <> #0) then<br> begin<br> if not ((PtrDirEnt.d_name[1] = '.') and (PtrDirEnt.d_name[2] = #0)) then<br> Attr := Attr or faHidden;<br> end;<br><br> if euidaccess(PChar(FName), W_OK) <> 0 then<br> Attr := Attr or faReadOnly;<br><br> if Attr and F.ExcludeAttr = 0 then<br> begin<br> F.Size := StatBuf.st_size;<br> F.Attr := Attr;<br> F.Mode := StatBuf.st_mode;<br> F.Name := PtrDirEnt.d_name;<br> F.Time := StatBuf.st_mtime;<br> Result := 0;<br> Break;<br> end;<br> end;<br> end;<br> Result := -1;<br> if readdir_r(F.FindHandle, @Scratch, PtrDirEnt) <> 0 then<br> Break;<br> end // End of While<br>end;<br>{$ENDIF}<br><br>function FindFirst(const Path: string; Attr: Integer;<br> var F: TSearchRec): Integer;<br>const<br> faSpecial = faHidden or faSysFile or faVolumeID or faDirectory;<br>{$IFDEF MSWINDOWS}<br>begin<br> F.ExcludeAttr := not Attr and faSpecial;<br> F.FindHandle := FindFirstFile(PChar(Path), F.FindData);<br> if F.FindHandle <> INVALID_HANDLE_VALUE then<br> begin<br> Result := FindMatchingFile(F);<br> if Result <> 0 then FindClose(F);<br> end else<br> Result := GetLastError;<br>end;<br>{$ENDIF}<br>{$IFDEF LINUX}<br>begin<br> F.ExcludeAttr := not Attr and faSpecial;<br> F.PathOnly := ExtractFilePath(Path);<br> F.Pattern := ExtractFileName(Path);<br> if F.PathOnly = '' then<br> F.PathOnly := IncludeTrailingPathDelimiter(GetCurrentDir);<br><br> F.FindHandle := opendir(PChar(F.PathOnly));<br> if F.FindHandle <> nil then<br> begin<br> Result := FindMatchingFile(F);<br> if Result <> 0 then<br> FindClose(F);<br> end<br> else<br> Result:= GetLastError;<br>end;<br>{$ENDIF}<br><br>function FindNext(var F: TSearchRec): Integer;<br>begin<br>{$IFDEF MSWINDOWS}<br> if FindNextFile(F.FindHandle, F.FindData) then<br> Result := FindMatchingFile(F) else<br> Result := GetLastError;<br>{$ENDIF}<br>{$IFDEF LINUX}<br> Result := FindMatchingFile(F);<br>{$ENDIF}<br>end;<br><br>procedure FindClose(var F: TSearchRec);<br>begin<br>{$IFDEF MSWINDOWS}<br> if F.FindHandle <> INVALID_HANDLE_VALUE then<br> begin<br> Windows.FindClose(F.FindHandle);<br> F.FindHandle := INVALID_HANDLE_VALUE;<br> end;<br>{$ENDIF}<br>{$IFDEF LINUX}<br> if F.FindHandle <> nil then<br> begin<br> closedir(F.FindHandle);<br> F.FindHandle := nil;<br> end;<br>{$ENDIF}<br>end;