Jump to content

binary data


yucatan
 Share

Recommended Posts

hello guys i have a file and that file is constandly getting bigger

i'm trying to read that file and save it on another location on my hard drive but when the script it done the new file is incomplete

i miss some data because i cant use the file

here is the code

$sfile = FileOpenDialog("Select file", @Desktopdir", "Images (*.mp3)", 1 + 4 )
$MyDocsFolder = "::{450D8FBA-AD25-11D0-98A8-0800361B1103}"
$var = FileSaveDialog( "Choose a name.", $MyDocsFolder, "demos (*.mp3)", 2)
;$var = FileSaveDialog( "Choose a name.", $MyDocsFolder, "Scripts (*.mp3;*.au3)", 2)
;ConsoleWrite(@CRLF&$iFileOp&@CRLF)
#Include <Array.au3>
$read1 = ""
$teller="0"
While 1 ;start a loop
$iFileOp = FileOpen($sFile, 16)  
;file is open start reading size
if $read1 = "" Then $read1 = FileRead($ifileop) ;this always repeat
$b1 = BinaryLen($read1)
$size = FileGetSize($sfile)

do
$teller +=1
$size1 = FileGetSize($sfile)
until $size1 > $size or $teller = 2000000000
            if $teller = 2000000000 then 
                MsgBox(4096, "Test", "error", 10)
                Exit
            EndIf
$teller = "0"
$iFileOp = FileOpen($sFile, 16)
$read2 = FileRead($ifileop) ;this always repeat
$b2 = BinaryLen($read2)

$result = BinaryMid($read2, $b1)
$result2 = BinaryLen($result)
ConsoleWrite("the old len was "&$b1&" the new len is "&$b2&" the added binary data is "&$result2&@CRLF)

;$b3 =$b2 - $b1
;ConsoleWrite($b3&@CRLF)
If FileExists($var) Then
    FileWrite($var,$result)
    FileClose($var)
Else
    FileWrite($var,$read1)
    FileClose($var)
EndIf

$read1 = $read2
WEnd
Link to comment
Share on other sites

hello guys i have a file and that file is constandly getting bigger

i'm trying to read that file and save it on another location on my hard drive but when the script it done the new file is incomplete

i miss some data because i cant use the file

here is the code

$sfile = FileOpenDialog("Select file", @Desktopdir", "Images (*.mp3)", 1 + 4 )
$MyDocsFolder = "::{450D8FBA-AD25-11D0-98A8-0800361B1103}"
$var = FileSaveDialog( "Choose a name.", $MyDocsFolder, "demos (*.mp3)", 2)
;$var = FileSaveDialog( "Choose a name.", $MyDocsFolder, "Scripts (*.mp3;*.au3)", 2)
;ConsoleWrite(@CRLF&$iFileOp&@CRLF)
#Include <Array.au3>
$read1 = ""
$teller="0"
While 1 ;start a loop
$iFileOp = FileOpen($sFile, 16)  
;file is open start reading size
if $read1 = "" Then $read1 = FileRead($ifileop) ;this always repeat
$b1 = BinaryLen($read1)
$size = FileGetSize($sfile)

do
$teller +=1
$size1 = FileGetSize($sfile)
until $size1 > $size or $teller = 2000000000
            if $teller = 2000000000 then 
                MsgBox(4096, "Test", "error", 10)
                Exit
            EndIf
$teller = "0"
$iFileOp = FileOpen($sFile, 16)
$read2 = FileRead($ifileop) ;this always repeat
$b2 = BinaryLen($read2)

$result = BinaryMid($read2, $b1)
$result2 = BinaryLen($result)
ConsoleWrite("the old len was "&$b1&" the new len is "&$b2&" the added binary data is "&$result2&@CRLF)

;$b3 =$b2 - $b1
;ConsoleWrite($b3&@CRLF)
If FileExists($var) Then
    FileWrite($var,$result)
    FileClose($var)
Else
    FileWrite($var,$read1)
    FileClose($var)
EndIf

$read1 = $read2
WEnd
I find your script a bit hard to understand :)

You open the file to read every loop but never close it?

I would thuink this

$result = BinaryMid($read2, $b1)

should be

$result = BinaryMid($read2, $b1+1)

If the file exists you write the extra data since the first read so all the first read is missing, if the file doesn't exist you write the first read leaving out the extra data.

Could you just say

Global $oldsize, $newsize
Global $maxgrowth = 500
While 1
    Sleep(500)
    $newsize = FileGetSize($sfile)
    If $newsize >= $oldsize + $maxgrowth Then
        FileCopy($sfile, $var)
        ConsoleWrite("copied file, now " & $newsize - $oldsize & " bytes larger." & @CRLF)
        $oldsize = $newsize
    EndIf
WEnd

and don't worry about all the binary bits and complications.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

I find your script a bit hard to understand :)

You open the file to read every loop but never close it?

I would thuink this

$result = BinaryMid($read2, $b1)

should be

$result = BinaryMid($read2, $b1+1)

If the file exists you write the extra data since the first read so all the first read is missing, if the file doesn't exist you write the first read leaving out the extra data.

Could you just say

Global $oldsize, $newsize
Global $maxgrowth = 500
While 1
    Sleep(500)
    $newsize = FileGetSize($sfile)
    If $newsize >= $oldsize + $maxgrowth Then
        FileCopy($sfile, $var)
        ConsoleWrite("copied file, now " & $newsize - $oldsize & " bytes larger." & @CRLF)
        $oldsize = $newsize
    EndIf
WEnd

and don't worry about all the binary bits and complications.

hahahaha omfg i have tested it and your right its fixen now thank god:D realy thx mate

i shall explane what my script does

i have a file and thats is constandly getting bigger what my script does is stream the file to a server

so when the file gets any bigger he send the new binary data to the server and he does that until the file is getting bigger then he gives a error and the script exit thats how it works now:D:D realy thx mate

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