根据文件路径检测文件大小并检测是否正在被占用
2016-11-11 00:00
441 查看
function CheckFileSize(sPath: string): Int64; var FilePath: AnsiString; FStream:TFileStream; bOpen:Boolean; //判断文件FileName是否正在被打开/使用 function IsFileInUse(const FileName: string): boolean; var HFileRes: HFILE; begin if not FileExists(FileName) then begin Result := False; Exit; end; try HFileRes := CreateFile(pchar(FileName), GENERIC_READ, 0 {this is the trick!}, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); Result := (HFileRes = INVALID_HANDLE_VALUE); if not Result then CloseHandle(HFileRes); except Result := true; end; end; begin try try IsFileInUse(sPath); if FileExists(sPath) then begin bOpen := false; while not bOpen do begin try IsFileInUse(sPath); FStream := TFileStream.Create(sPath, fmOpenWrite); bOpen := true; except on E: Exception do bOpen := false; end; end; FStream.Position := FStream.Size; Result := FStream.Size; end else begin FStream := TFileStream.Create(sPath, fmCreate); Result := 0; end; except on e: Exception do begin Result := -2; end; end; finally FreeAndNil(FStream); end; end;
相关文章推荐
- 根据文件路径检测文件大小并检测是否正在被占用
- 根据文件路径检测文件大小并检测是否正在被占用
- 【文件操作】文件重命名 & 检测文件是否被占用
- python 判断路径是文件还是文件夹、判断是否存在、获取文件大小
- C#检测是否文件是否被其他进程占用
- OC中根据文件路径获取文件大小
- c++判断文件是否存在,判断是文件还是目录,获取文件大小,获取程序所在路径
- 使用c#检测文件正在被那个进程占用
- android执行外部命令、检测文件是否存在、自动检测U盘路径
- IOS检测指定路径的文件是否存在
- 监测程序详细介绍,快捷键的设置;txt文件里面一行行的读取、删除、添加字符串等;根据程序路径名以及程序名判断程序是否在运行;
- 【C#】判断文件是否正在被其他进程占用
- IOS根据路径读取文件大小
- 根据路径获得文件大小
- IOS检测指定路径的文件是否存在
- 使用c#检测文件正在被那个进程占用
- iOS小demo之根据路径获取文件大小
- IOS根据路径读取文件大小
- C# 检测文件是否被其他进程占用的几种方法
- 检测一个文件是否正在使用