(评分: , 回复: 0, 阅读: 85) // 判断文件是否正在使用 function IsFileInUse(FName: string): Boolean; var HFileRes: HFILE; begin Result := False; if not FileExists(FName) then Exit; HFileRes := CreateFile(PChar(FName), GENERIC_READ or GENERIC_WRITE, 0, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); Result := (HFileRes = INVALID_HANDLE_VALUE); if not Result then CloseHandle(HFileRes); end;
{ 功能说明:查找一个路径下的所有文件。 参数:path:路径, filter:文件扩展名过滤, FileList:文件列表, ContainSubDir:是否包含子目录} procedure FindFileList(Path,Filter:string;FileList:TStrings;ContainSubDir:Boolean); var FSearchRec,DSearchRec:TSearchRec; FindResult:shortint; begin FindResult:=FindFirst(path+Filter,sysutils.faAnyFile,FSearchRec);
try while FindResult=0 do begin FileList.Add(FSearchRec.Name); FindResult:=FindNext(FSearchRec); end; if ContainSubDir then begin FindResult:=FindFirst(path+Filter,faDirectory,DSearchRec); while FindResult=0 do begin if ((DSearchRec.Attr and faDirectory)=faDirectory) and (DSearchRec.Name<>'.') and (DSearchRec.Name<>'..') then FindFileList(Path,Filter,FileList,ContainSubDir); FindResult:=FindNext(DSearchRec); end; end; finally FindClose(FSearchRec); end; end; // 取文件夹文件数 function GetDirFiles(Dir: string): Integer; var sr: TSearchRec; fr: Integer; begin Result := 0; fr := FindFirst(AddDirSuffix(Dir) + '*.*', faAnyFile, sr); while fr = 0 do begin if (sr.Name <> '.') and (sr.Name <> '..') then Inc(Result); fr := FindNext(sr); end; FindClose(sr); end;
2005-12-28 11:42:27
|