//********** // Function: Create Sparse Files // Input value: FileName: Sparse File Name // FileSize: Sparse File Size // Result value: True: True or False // Author: 果子 // Create Date: 2006.05.02 //**********
function CreateSparseFile(const FileName: String; const FileSize: Int64): Boolean; var hF: THandle; dirStr: String; Temp: DWORD; begin dirStr := ExtractFileDir(FileName) ; if not DirectoryExists(dirStr) then ForceDirectories(dirStr); //创建目录 hF := CreateFile(Pchar(FileName), GENERIC_WRITE, 0, nil, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL or FILE_FLAG_SEQUENTIAL_SCAN, 0); result := (hf <> INVALID_HANDLE_VALUE); DeviceIOControl(hF, 590020, nil, 0, nil, 0, Temp, nil); SetFilePointer(hF, Int64Rec(FileSize).Lo, @Int64Rec(FileSize).Hi, FILE_BEGIN); SetEndOfFile(hF); CloseHandle(hF); end; |