Jump to content

Recommended Posts

Posted

I have a file (3.43GB) and need to remove the last 5 bytes, without copying first (3.43GB - 5bytes). How?

thanks.

_____________________________________________________________________________

Posted

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)
Posted (edited)

(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
Posted

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)

Posted

To @Manjish and @dbzfanatic, - Neither that, nor another:) I haven't enough free space to copy first 3.43Gb-5Bytes, and I haven't enough RAM to do that so, like you say..

_____________________________________________________________________________

Posted

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

_____________________________________________________________________________

Posted

- 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

Posted

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)

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
×
×
  • Create New...