Jump to content

Set position in file


Recommended Posts

Hi.

_FileSetPosAPI , or included as 3rd parameter in _FileReadAPI, _FileWriteAPI

eg

;apitry2.au3

#include "APITailRW.au3"

Local $sDeskFile = @DesktopDir & "\Rhododendron.bmp", $s_File = @WindowsDir & "\Rhododendron.bmp"

Local $i_FileSize = FileGetSize($s_File), $iMod = $i_FileSize - 4 * Int($i_FileSize / 4)

;======Read parts or tail of binary file =====in any order as Demo =================================

$h_File = _FileOpenAPI ($s_File) ;_APIFileOpen

$s_data2 = _FileReadAPI ($h_File, Int($i_FileSize / 4), 1 * Int($i_FileSize / 4), 1) ; read 2nd quarter file

$s_data1 = _FileReadAPI ($h_File, Int($i_FileSize / 4), 0 * Int($i_FileSize / 4), 1) ; read 1st quarter file

$s_data4 = _FileReadAPI ($h_File, Int($i_FileSize / 4) + $iMod, 3 * Int($i_FileSize / 4), 1) ; read 4th quarter file

$s_data3 = _FileReadAPI ($h_File, Int($i_FileSize / 4), 2 * Int($i_FileSize / 4), 1) ; read 3rd quarter file

$s_data = $s_data1 & $s_data2 & $s_data3 & $s_data4 ; concatenate in correct order

_FileCloseAPI ($h_File);_APIFileClose

;======Save binary file to desktop and open==========in any order as Demo ==================================

Local $iDel=FileDelete($sDeskFile), $hb_File = _FileOpenAPI ($sDeskFile) ;_FileOpenAPI

;======Set End of file related to $FileSize=================================

_FileSetPosAPI ($hb_File, $i_FileSize)

_FileSetEndAPI ($hb_File)

;======Set Data pieces================in any order as Demo ======================

_FileWriteAPI ($hb_File, $s_data3, 2 * Int($i_FileSize / 4), 1);_APIFileWrite($hFile, $szData, $i_FileSetPosAPI = -1, $Option = 0)

_FileWriteAPI ($hb_File, $s_data1, 0 * Int($i_FileSize / 4), 1);_APIFileWrite($hFile, $szData, $i_FileSetPosAPI = -1, $Option = 0)

_FileWriteAPI ($hb_File, $s_data4, 3 * Int($i_FileSize / 4), 1);_APIFileWrite($hFile, $szData, $i_FileSetPosAPI = -1, $Option = 0)

_FileWriteAPI ($hb_File, $s_data2, 1 * Int($i_FileSize / 4), 1);_APIFileWrite($hFile, $szData, $i_FileSetPosAPI = -1, $Option = 0)

_FileCloseAPI ($hb_File);_FileCloseAPI

ShellExecuteWait($sDeskFile)

FileDelete($sDeskFile)

Best, Randall
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...