AzKay Posted April 24, 2008 Share Posted April 24, 2008 Ive wanted to make a function to add/remove 0x0 from files, until the size is X. Ive got; $File = "" $Bytes = "" Do $File = FileOpen($File, 1+16) FileWrite($File, 0) FileClose($File) Until FileGetSize($File) == $Bytes But, this only makes the file bigger. I want to do the reverse, remove the last characters until its X size. # MY LOVE FOR YOU... IS LIKE A TRUCK- # Link to comment Share on other sites More sharing options...
ProgAndy Posted April 24, 2008 Share Posted April 24, 2008 $FilePAth = "" $Bytes = "" $File = FileOpen($FilePAth, 1+16) $File2 = FileOPen($FilePAth&".tmp", 1+16) FileWrite($File2,FileRead($File,$bytes)) ; Reads Given amount of bytes and writes them to an new File FileClose($file) FileClose($file2) FileDelete($FilePATH) FileMove($FilePATH&".tmp",$FILEPATH) *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes Link to comment Share on other sites More sharing options...
AzKay Posted April 24, 2008 Author Share Posted April 24, 2008 Thanks :3 # MY LOVE FOR YOU... IS LIKE A TRUCK- # Link to comment Share on other sites More sharing options...
AzKay Posted April 24, 2008 Author Share Posted April 24, 2008 Know of a more memory efficient way? I just tried it on an 800mb file, and itll just hang. Also, using making the computer go really slow. Requiring me to restart, because nor taskmanager, or process explorer, would kill it. # MY LOVE FOR YOU... IS LIKE A TRUCK- # Link to comment Share on other sites More sharing options...
AzKay Posted April 24, 2008 Author Share Posted April 24, 2008 Hmm, I ended up using some VB6 code. If anyones interested, I could rewrite it in autoit. # MY LOVE FOR YOU... IS LIKE A TRUCK- # Link to comment Share on other sites More sharing options...
Siao Posted April 24, 2008 Share Posted April 24, 2008 Know of a more memory efficient way?Bunch of DllCalls to WinAPI functions: CreateFile+SetFilePointer+SetEndOfFile+CloseHandle "be smart, drink your wine" Link to comment Share on other sites More sharing options...
zorphnog Posted April 24, 2008 Share Posted April 24, 2008 Maybe something like this: Func _FileSplit($sFilename, $iOutfileBytes) Local $hInfile, $iInfileBytes, $sFile, $i=0 $iInfileBytes = FileGetSize($sFilename) If $iInfileBytes > $iOutfileBytes Then $hInfile = FileOpen($sFilename, 16) $sFile = FileRead($hInfile, $iOutfileBytes) While @error <> -1 $i += 1 FileWrite(StringFormat($sFilename & ".%04d",$i), $sFile) $sFile = FileRead($hInfile, $iOutfileBytes) WEnd EndIf EndFunc Link to comment Share on other sites More sharing options...
AzKay Posted April 24, 2008 Author Share Posted April 24, 2008 Bunch of DllCalls to WinAPI functions: CreateFile+SetFilePointer+SetEndOfFile+CloseHandleYeah, Thats the VB6 code I used.Not quite working out in autoit though, It keeps giving me "unknown revision", Or something along those lines. # MY LOVE FOR YOU... IS LIKE A TRUCK- # Link to comment Share on other sites More sharing options...
AzKay Posted April 24, 2008 Author Share Posted April 24, 2008 K, Scrapped half the DLLCalls, Founds them in the _WinAPI_ functions. Used those instead, Finnished product: #Include <WinAPI.au3> SetFileSize("test.txt", 6) Func SetFileSize($FileName, $newSize) $fileHandle = _WinAPI_CreateFile($FileName, 2) DllCall("kernel32.dll", "long", "SetFilePointer", "long", $fileHandle, "long", $newSize, "long", 0, "long", 0) DllCall("kernel32.dll", "long", "SetEndOfFile", "long", $fileHandle) _WinAPI_CloseHandle($fileHandle) EndFunc :3 # MY LOVE FOR YOU... IS LIKE A TRUCK- # Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now