具体的には、
ABCDENDKHILHLBKIGVABCNLHKUGJFYHGBBHKBJBVGUABCBUGIIGBLIY
というようなファイルがあったとして、デリミタにABCを指定すると、
ABCDENDKHILHLBKIGV
ABCNLHKUGJFYHGBBHKBJBVGU
ABCBUGIIGBLIY
の3ファイルが出力されるようなツールです。
perlのsplit関数でできます。Winでもperlをいれれば。
http://chaichan.web.infoseek.co.jp/perlnote/perlnote2007-05-28.h...
バイナリを任意のデリミタ(文字列)で分割というのは思い当たらないので、
EXCEL の VBA での実装例です。
上記のデータファイルが BinData.dat であった場合、同じフォルダ内へ
BinData_1.dat, BinData_2.dat, BinData_3.dat として分割されます。
Option Explicit Sub main() sepFile "C:\BinData.dat", "ABC" End Sub Sub sepFile(inFilePath$, delm$) Dim fso As Object Set fso = CreateObject("Scripting.FileSystemObject") '--- ファイルチェック If fso.FileExists(inFilePath) = False Then MsgBox (inFilePath & "がありません") Exit Sub End If '--- 文字列変数宣言 Dim folderPath$, fileExt$, fileBase$, outFileName$ folderPath = fso.GetFile(inFilePath).ParentFolder fileExt = fso.GetExtensionName(inFilePath) fileBase = Replace(fso.GetFile(inFilePath).Name, "." & fileExt, "") Dim fileSize As Long fileSize = fso.GetFile(inFilePath).Size '--- 整数型変数宣言 Dim i&, j& '-- Long Dim outFileNum%, iFF%, oFF% '-- Integer Dim tmpByte As Byte, inByte As Byte outFileNum = 1 outFileName = folderPath & "\" & fileBase & "_" & outFileNum & "." & fileExt '--- バイナリモードで開く iFF = FreeFile Open inFilePath For Binary As #iFF oFF = FreeFile Open outFileName For Binary As #oFF Dim delmPos As Integer delmPos = 0 For i = 1 To fileSize Get #iFF, , inByte '--- デリミタとマッチしないとき、バッファを出力 If inByte <> CByte(Asc(Mid(delm, delmPos + 1, 1))) Then If delmPos > 0 Then For j = 1 To delmPos tmpByte = CByte(Asc(Mid(delm, j, 1))) Put #oFF, , tmpByte Next delmPos = 0 End If End If '--- デリミタとマッチチェック If inByte = CByte(Asc(Mid(delm, delmPos + 1, 1))) Then '--- バッファリング delmPos = delmPos + 1 '--- マッチしたら、ファイルを切り替え If delmPos = Len(delm) Then Close #oFF outFileNum = outFileNum + 1 outFileName = folderPath & "\" & fileBase & "_" & outFileNum & "." & fileExt Open outFileName For Binary As #oFF '--- デリミタを出力 For j = 1 To Len(delm) tmpByte = CByte(Asc(Mid(delm, j, 1))) Put #oFF, , tmpByte Next delmPos = 0 End If Else '--- マッチしなければ出力 Put #oFF, , inByte End If Next '--- バッファが残っていれば出力 If delmPos > 0 Then For j = 1 To delmPos tmpByte = CByte(Asc(Mid(delm, j, 1))) Put #oFF, , tmpByte Next delmPos = 0 End If Close #iFF Close #oFF End Sub
また main の部分を下記のように変え、ファイルパスを列挙したセルを選択して実行すれば、
複数ファイルを一括して処理することもできます。
Sub main() Dim r As Range For Each r In Selection sepFile r.Value, "ABC" Next End Sub
http://www.cocoaliz.com/excelVBA/index/47/
これってバイナリも扱えるものでしょうか?