copy /B safe ?
Moderator: DosItHelp
copy /B safe ?
Hi, I've added the /B switch to the copy command of my fileCopy function, because otherwise if i join files x + y > z the result is a corrupted file of only a few bytes. But I was wondering if it's safe to add the /B switch to the copy command of my fileCopy function and forget about it.
-
- Expert
- Posts: 1167
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
Re: copy /B safe ?
It will join the two files at a binary level, simply appending the data of the second file to the end of the first file. When you do this with text files, it acts the same as the >> command. When you join two unrelated files of different file types (say, a JPEG and a RAR file), you can use the same file as both types.
Re: copy /B safe ?
sorry, I cannot follow your answer, I only expect the result of 'copy x > z' AND 'copy x + y > z' to be an identical copy of x OR x + y.
As far as I know, leaving out /B on non ascii files result in a corrupted file, I want to know whether including /B will always result in a non-corrupted file.
yes, don't understand, if I join a .rar and a .jpeg file, I should get a corrupted file that is neither rar nor jpeg, because the rar part prevents it to render as jpeg and vice versa not ?
I have another question which is unrelated to the initial question, joining files is cool, but I want to split files aswell, manually splitting files using hackman hex editor is a pain.
As far as I know, leaving out /B on non ascii files result in a corrupted file, I want to know whether including /B will always result in a non-corrupted file.
yes, don't understand, if I join a .rar and a .jpeg file, I should get a corrupted file that is neither rar nor jpeg, because the rar part prevents it to render as jpeg and vice versa not ?
I have another question which is unrelated to the initial question, joining files is cool, but I want to split files aswell, manually splitting files using hackman hex editor is a pain.
-
- Expert
- Posts: 1167
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
Re: copy /B safe ?
If you join a rar and a jpeg with copy /b, you can open it in an image viewer and still extract the file inside of it with WinRAR.
https://mega.co.nz/#!EBYkhZoJ!kUvK-RFI6 ... XNU0EPHl3I
Download this and change the extension to .png
https://mega.co.nz/#!EBYkhZoJ!kUvK-RFI6 ... XNU0EPHl3I
Download this and change the extension to .png
-
- Expert
- Posts: 1167
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
Re: copy /B safe ?
Although playing with it some more, it looks like this only works if you use
and not
As far as I can tell, WinRAR looks for the archive header anywhere in the file's binary and skips anything preceding it.
Code: Select all
copy /b source.png+source.rar target.png
and not
Code: Select all
copy /b source.rar+source.png target.png
As far as I can tell, WinRAR looks for the archive header anywhere in the file's binary and skips anything preceding it.
-
- Posts: 66
- Joined: 13 Jan 2015 06:55
Re: copy /B safe ?
Ed Dyreen wrote:yes, don't understand, if I join a .rar and a .jpeg file, I should get a corrupted file that is neither rar nor jpeg, because the rar part prevents it to render as jpeg and vice versa not ?
It's much alike those .bat/.js hybrids - both .rar and .jpeg file formats have specific header, like these (simplified):
Code: Select all
JPEG_MAGIC_BYTES | JPEG_FILE_PART_SIZE | IMAGE_INFO
RAR_MAGIC_BYTES | RAR_FILE_PART_SIZE | ARCHIVE_INFO
Ed Dyreen wrote:
I have another question which is unrelated to the initial question, joining files is cool, but I want to split files aswell, manually splitting files using hackman hex editor is a pain.
Please more specifically, it's no universal way. You must now at least (grouped):
[1st/2nd file size]
[1st/2nd file format, this format has header in which file size is specified]
[1st/2nd file content]
EDIT: Read https://en.wikipedia.org/wiki/File_format
Re: copy /B safe ?
Ed Dyreen wrote:
I have another question which is unrelated to the initial question, joining files is cool, but I want to split files aswell, manually splitting files using hackman hex editor is a pain.
check this - http://stackoverflow.com/questions/2824 ... -script-wi
Wihtout /B switch copy+ tries should remove end of file symbol (♀) at the end of files , but I'm not sure how it is done and what the result is (will it try to replace every eof symbol or just last symbol of every file?).I suppose it can be easy checked with any hex editor .
Re: copy /B safe ?
Allright then, I'll just see how it goes.npocmaka_ wrote:Wihtout /B switch copy+ tries should remove end of file symbol (♀) at the end of files , but I'm not sure how it is done and what the result is (will it try to replace every eof symbol or just last symbol of every file?).I suppose it can be easy checked with any hex editor .
Re: copy /B safe ?
Ed Dyreen wrote:if I join a .rar and a .jpeg file, I should get a corrupted file that is neither rar nor jpeg
You get a concatenated file, neither part of the binary file is damaged, and both can be extracted again with no corruption when using /B
Copy without the /B switch stops on an EOF character.
A binary file has EOF as a legal character and which is not an EOF marker.
You can leave the /B switch in all the time - being aware that two text files can join awkwardly when CR/LF pairs are not at the beginning/end of the files.
I have another question which is unrelated to the initial question, joining files is cool, but I want to split files aswell, manually splitting files using hackman hex editor is a pain.
I have some scripts/tools to split/join files. What filesizes are you planning to use.
Re: copy /B safe ?
ah thanks foxi, that's pretty clear now, I will hardly ever use my fileCopy_ function to join files, but I want it to be able to do at least what normal copy command can. The situation u describe will probably never happen and when it does I'll know why. I can always add an /asciiMode option if I find it that important later..
The files I want to have automatically split are about 1.5GB in size. I manually compare them with Hackman, I examine where they are different so I know where their header ends and then I cut off the header which I must then join, to restore the file.
I may be able to automate the comparing with the fc command, but the splitting is still on the drawing table..
I do not want adobe or .NET dependencies, I was thinking about makecab or certutil.
The files I want to have automatically split are about 1.5GB in size. I manually compare them with Hackman, I examine where they are different so I know where their header ends and then I cut off the header which I must then join, to restore the file.
I may be able to automate the comparing with the fc command, but the splitting is still on the drawing table..
I do not want adobe or .NET dependencies, I was thinking about makecab or certutil.
Re: copy /B safe ?
Ed Dyreen wrote:
I do not want adobe or .NET dependencies, I was thinking about makecab or certutil.
adodb streams have nothing to do with adobe

Re: copy /B safe ?
Ed Dyreen wrote:The files I want to have automatically split are about 1.5GB in size. I manually compare them with Hackman, I examine where they are different so I know where their header ends and then I cut off the header which I must then join, to restore the file.
What is the task doing? It seems to be more than splitting files into chunks.
Are they video files and you are processing them in some way?
Re: copy /B safe ?
They are data files, I cut off their headers and join them later. They can contain any data, but their headers are all similar. They are not processed in any way after they've been cut.foxidrive wrote:What is the task doing? It seems to be more than splitting files into chunks.
Are they video files and you are processing them in some way?
Re: copy /B safe ?
Ed Dyreen wrote:They are data files, I cut off their headers and join them later. They can contain any data, but their headers are all similar. They are not processed in any way after they've been cut.foxidrive wrote:What is the task doing? It seems to be more than splitting files into chunks.
Are they video files and you are processing them in some way?
We know no more about the task than before.
Re: copy /B safe ?
I just told you they are huge (1.5GB) windows binaries. What more is there to say, they can contain any data yet an understanding of this data should not be required for the splitting process. The only thing relevant is maxFileSize and an efficient way to automate the split process at offSet, just like I do currently with hackman. If you don't understand the requirement then don't bother responding.foxidrive wrote:We know no more about the task than before.