In a batch script the copy command allows the following usage:
copy /b first.bin + /b second.bin /b merged.bin
Is it possible to do something like this* in AHK?**
* I.e. to concatenate binary and/or text files, but potentially with unicode characters in file names.
** Not by using DOS commands in the AHK script; not by reading file's content and using FileAppend...
FileCopy like in DOS: copy file1 + file2 mergedfile Topic is solved
-
- Posts: 493
- Joined: 24 Aug 2016, 03:34
Re: FileCopy like in DOS: copy file1 + file2 mergedfile
[code]FileRead, bin_First, first.bin
FileRead, bin_Second, second.bin
FileDelete, merged.bin
FileAppend, %bin_First%, merged.bin
FileAppend, %bin_Second%, merged.bin
[/code]I hope that helps.
alternative: FileCopy for first component.
alternative: use FileObject (most useful for unicode names / binary content)
Last edited by wolf_II on 17 Jun 2018, 05:45, edited 1 time in total.
Re: FileCopy like in DOS: copy file1 + file2 mergedfile
Have you edited in the meantime? IDK, maybe my brain is too weak to remember.
In any case, use a FileObject.
In any case, use a FileObject.
Re: FileCopy like in DOS: copy file1 + file2 mergedfile Topic is solved
Try this:
Code: Select all
q:: ;concatenate 2 binary files
vPath1 := A_Desktop "\first.bin"
vPath2 := A_Desktop "\second.bin"
vPathOut := A_Desktop "\merged.bin"
FileGetSize, vSize1, % vPath1
FileGetSize, vSize2, % vPath2
vSize := vSize1 + vSize2
VarSetCapacity(vData, vSize)
vOffset := 0
Loop, 2
{
if !oFile := FileOpen(vPath%A_Index%, "r")
return
oFile.Pos := 0
oFile.RawRead(&vData+vOffset, oFile.Length)
vOffset += oFile.Length
oFile.Close()
}
if !oFile := FileOpen(vPathOut, "w") ;empties file if it already exists
return
oFile.RawWrite(&vData, vSize) ;appends data, advances pointer
oFile.Close()
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
-
- Posts: 493
- Joined: 24 Aug 2016, 03:34
Re: FileCopy like in DOS: copy file1 + file2 mergedfile
Great, jeesweg, you are a schatz!
(And it is fast enough! I thought RawRead/Write will be pretty slow.)
(And it is fast enough! I thought RawRead/Write will be pretty slow.)
Re: FileCopy like in DOS: copy file1 + file2 mergedfile
@ newbieforever, you should consider jeeswg's code an example for you to rewrite as a (more general) function. If you are not interested, at least you should do vData := "".
Cheers.
Cheers.
-
- Posts: 493
- Joined: 24 Aug 2016, 03:34
Re: FileCopy like in DOS: copy file1 + file2 mergedfile
Thank you, helgef!
Or VarSetCapacity(vData, 0), isn't it so?
This should be done at the beginning or at the end of the script?
Or VarSetCapacity(vData, 0), isn't it so?
This should be done at the beginning or at the end of the script?
Re: FileCopy like in DOS: copy file1 + file2 mergedfile
VarSetCapacity(vData, 0) is fine, do it before the subroutine returns, you need to consider it in two places. If you make a function, it is not needed, since all local (non-static) variables will be made blank, equivalent to x := "", when the function returns.
There is a difference between varsetcapacity x, 0 and x := "",
There is a difference between varsetcapacity x, 0 and x := "",
Cheers.varsetcapacity wrote:For performance reasons, the memory of a variable whose capacity is less than 4096 bytes is not freed by storing an empty string in it (e.g. Var := ""). However, VarSetCapacity(Var, 0) does free it.