バイナリファイルの比較(VB6.0)_1  (No.1の個別表示) [スレッド一覧へ] |  
- 日時: 2011/04/05 10:46
- 名前: 花ちゃん
  
  - ***********************************************************************************
 * カテゴリー:[ファイル][ファイル入出力][]                                        * * キーワード:バイナリ,Binary,,,,                                              * *********************************************************************************** ----------------------------------------------------------------------------------- Re: バイナリファイルの比較 - Starfish  2006/10/06-00:18 No.7443  -----------------------------------------------------------------------------------
   こんな感じでもOKです。ファイルを読む前に、ファイルサイズのチェックをしたほうが まともでしょうが、適当に直して使ってください。
 
  Dim bytBuf1() As Byte Dim bytBuf2() As Byte
      Open "ホゲホゲ1.wav" For Binary As #1     Open "ホゲホゲ2.wav" For Binary As #2     bytBuf1 = InputB(LOF(1), #1)     bytBuf2 = InputB(LOF(2), #2)     Close #1, #2          If CStr(bytBuf1) = CStr(bytBuf2) Then         MsgBox "同じです。"     Else         MsgBox "違います。"     End If
   
 |  
  バイナリファイルの比較(VB6.0)_2  (No.2の個別表示) [スレッド一覧へ] |  
- 日時: 2011/04/05 10:46
- 名前: 花ちゃん
  
  - ***********************************************************************************
 * カテゴリー:[ファイル][ファイル入出力][]                                        * * キーワード:バイナリ,Binary,,,,                                              * *********************************************************************************** ----------------------------------------------------------------------------------- Re: バイナリファイルの比較 - も  2006/10/06-00:38 No.7444  -----------------------------------------------------------------------------------
  ちょっと私も後で使うので、作ってみました(少しだけテスト完了) テストとしては「DataBlockLenの整数倍にならないファイルの終端1バイトだけ変えたファイルをFalseとみなすか」というものしかやってません
  Public Function CompareFileData(ByVal FilePath1 As String, ByVal FilePath2 As String) As Boolean     'FilePath1とFilePath2の示すファイルのデータが等しければ真、等しくなければ偽     Const DataBlockLen  As Long = 1024& * 10 '10KBのブロックデータとして扱う     Dim ff1             As Integer     Dim ff2             As Integer     Dim FileLength      As Long     Dim i               As Long     Dim k               As Long     Dim buf1()          As Byte     Dim buf2()          As Byte     ReDim buf1(1 To DataBlockLen), buf2(1 To DataBlockLen)          'デフォルトでFalseを返す     CompareFileData = False          'ファイルの存在確認     If Not (ExistFile(FilePath1) And ExistFile(FilePath2)) Then Exit Function          'ファイル長の確認     FileLength = FileLen(FilePath1)     If Not (FileLength = FileLen(FilePath2)) Then Exit Function          'ファイルデータの確認     ff1 = FreeFile(): Open FilePath1 For Binary Access Read As ff1     ff2 = FreeFile(): Open FilePath2 For Binary Access Read As ff2         For i = 1 To FileLength Step DataBlockLen             If FileLength - i + 1 < DataBlockLen Then                 'ファイルの橋を切り詰める ※不必要かも                 ReDim buf1(1 To FileLength - i + 1), buf2(1 To FileLength - i + 1)             End If             Get #ff1, i, buf1()             Get #ff2, i, buf2()             For k = LBound(buf1) To UBound(buf1)                 If Not (buf1(k) = buf2(k)) Then                     '等しくない                     Exit Function                 End If             Next         Next     Close ff1, ff2          'ファイルのデータは等しかった     CompareFileData = True      End Function
  Private Function ExistFile(ByVal FilePath As String) As Boolean     On Error GoTo Error:         ExistFile = Not (GetAttr(FilePath) And vbDirectory) Error:     'ファイルではない End Function
   
  |  
  |