simonc said:
Is there a way in Windows or a Command Window of copying a specified
number
of bytes from a binary file to another file? I've got a very large binary
file and want to break it into smaller chunks to manipulate more easily.
Grateful for advice.
There are no native tools in Windows to do this. You need a file splitter
like the one below. Here is what you need to do:
1. Copy and paste the code into c:\Split.vbs. Make sure to have a .vbs file
extension!
2. Click Start / Run
3. Type the three letters cmd and click OK.
4. Type the following command:
cscript c:\split.vbs "c:\Documents and Settings\SimonC\BigFile.bin" xxx
c:\
Instead of "xxx", type the desired chunk size in kBytes.
5. Press the Enter key.
This will give you a number of file chunks named c:\BigFile.001,
c:\BigFile.002 etc.
'--------------------------------
'Split a file into smaller chunks
'8.4.2008 FNL
'--------------------------------
LF = Chr(10)
Dim oFSO, FullName, Path, Name, Size, TargetDir
Set oFSO = CreateObject("Scripting.FileSystemObject")
WScript.Echo
Parms
Split
'-----------------------------------
'Process the command line parameters
'-----------------------------------
Sub Parms
Dim oArgs
Set oArgs = WScript.Arguments
If oArgs.Count <> 3 Then Error _
("Incorrect number of parameters." & LF & LF _
& "Usage: Split FullName Size TargetDrive" & LF _
& "State desired output file size in kBytes!")
FullName = oArgs(0)
Path = oFSO.GetParentFolderName(oArgs(0))
Name = oFSO.GetBaseName(oArgs(0)) & "."
Size = 1000 * oArgs(1)
TargetDir = Left(oArgs(2),1) & ":\"
End Sub
'--------------
'Split the file
'--------------
Sub Split
Dim iFile, oFile, iStream, Data
Dim Ext, e, offset, length, NewName
if not oFSO.FileExists(FullName) then Error _
("Cannot locate the file """ & FullName & """")
Set iFile = oFSO.GetFile(FullName)
On Error Resume Next
Set iStream = iFile.OpenAsTextStream(1)
if err.number > 0 then Error("Cannot open the file """ & FullName _
& """" & LF & Err.Description)
On Error Goto 0
Data = iStream.Read(iFile.Size)
iStream.close
Ext = 0
offset = 1
Do
Ext = Right("00" & Ext + 1, 3)
if ext > "999" then Error ("Too many files - maximum is 999!")
NewName = TargetDir & Name & Ext
WScript.Echo "Writing """ & NewName & """"
On Error Resume Next
Set oFile = oFSO.CreateTextFile(NewName, 2)
if err.number > 0 then Error("Cannot open the file """ _
& NewName & """" & LF & Err.Description)
On Error Goto 0
length = Size
If length > Len(data)+1 - offset Then length = Len(data) + 1 - offset
oFile.Write Mid(Data, offset, length)
offset = offset + length
oFile.Close
Loop Until offset >= Len(data)
End Sub
'----------
'Error exit
'----------
Sub Error (Message)
WScript.Echo Message
WScript.Quit
End Sub