Jump to content

How to delete last "x" bytes in file?


Recommended Posts

This is all I can think of. I haven't tested it, just wrote it here. Hope it works for you.

$file = FileOpen("filename",18)
$data = FileRead($file)
$bytes = StringSplit($data,"")
For $i = $bytes[0] - 6 To $bytes[0] - 1
$bytes[$i] = ""
Next
$new_data = _ArrayToString($bytes,"",1)
FileWrite($new_data)
Link to comment
Share on other sites

(Deleting my prev post)

Oh now I get what he means..

@dbz..

so u r assuming its a textfile? 3.43 gb large? kind of unlikely don't you think?

Edited by Manjish
[font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com
Link to comment
Share on other sites

Try

#include <WinAPI.au3>

$sFile = @ScriptDir & "\largefile"
$iTrim = 5    ; bytes to remove from end
$hFile = _WinAPI_CreateFile($sFile, 2, 4)
_WinAPI_SetFilePointer($hFile, FileGetSize($sFile) - $iTrim)
ConsoleWrite("Start " & $sFile & " " & FileGetSize($sFile) & " bytes" & @LF)
_WinAPI_SetEndOfFile($hFile)
_WinAPI_CloseHandle($hFile)
ConsoleWrite("Trimmed " & $sFile & " " & FileGetSize($sFile) & " bytes" & @LF)

Link to comment
Share on other sites

picaxe's version should work. It just opens the file,not copying it.

- Sould, but:

>Running:(3.3.0.0):C:\Program Files\AutoIt3\autoit3.exe.....

Start E\Fedora-11-i386-DVD.iso 0 bytes

and then MsgBox(0, "Error", "_WinApi_CloseHandle: Incorrect descriptor.")

_____________________________________________________________________________

Link to comment
Share on other sites

- Sould, but:

>Running:(3.3.0.0):C:\Program Files\AutoIt3\autoit3.exe.....

Start E\Fedora-11-i386-DVD.iso 0 bytes

and then MsgBox(0, "Error", "_WinApi_CloseHandle: Incorrect descriptor.")

Hi,

Start E\Fedora-11-i386-DVD.iso

Have a look at file name. There is a : missing

;-))

Stefan

Link to comment
Share on other sites

This is better and should work for files > 2^32 bytes

#include <WinAPI.au3>

$sFile = @ScriptDir & "\zzz.avi"
$iTrim = 5    ; bytes to remove from end
$hFile = _WinAPI_CreateFile($sFile, 2, 4)
_WinAPI_SetFilePointer($hFile, - $iTrim, 2)
ConsoleWrite("Start " & $sFile & " " & FileGetSize($sFile) & " bytes" & @LF)
_WinAPI_SetEndOfFile($hFile)
_WinAPI_CloseHandle($hFile)
ConsoleWrite("Trimmed " & $sFile & " " & FileGetSize($sFile) & " bytes" & @LF)

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...