Connecting Tech Pros Worldwide Help | Site Map

how to trap an error reading CDrom

Newbie
 
Join Date: Oct 2009
Posts: 18
#1: Oct 12 '09
I'm writing a program that list the contents of a CDrom and also the contents of the ZIP files.
When there is a bad Zip file on the CD, the program keeps traying to reed the file and after +- 50 times it gives the error and ends the function.
This function is called from an other function that scans al the files on the disc.
Is it possible to give an error but that the program continues with the next file ?
=============================
FUNCTION THAT SCANS THE FOLDER

Expand|Select|Wrap|Line Numbers
  1. Private Function Write_Files(ByVal START_FOLDER)
  2. Dim DE_FILE As Scripting.File
  3. Dim SUBFOLDER As Scripting.Folder
  4.    Label_List_FolderBezig.Caption = START_FOLDER
  5.    Label_List_FolderBezig.Refresh
  6.    For Each DE_FILE In START_FOLDER.Files
  7.       On Error GoTo Volgende
  8.       Call Write_In_Textbox(DE_FILE.PATH)
  9. Volgende:
  10.    Next
  11.    For Each SUBFOLDER In START_FOLDER.SubFolders
  12.       Call Write_Files(SUBFOLDER)
  13.    Next
  14. End Function
  15.  
========================================
FUNCTION WRITING THE CONTENTS OF THE FILE

Expand|Select|Wrap|Line Numbers
  1. Private Function Write_In_Textbox(ByVal PATH_FILENAME As String)
  2. Dim FileName As String
  3. Dim LENGTE As String
  4. '§ == for listing ZIP files ==
  5. Dim ReadHead As typZipLocalFileHead
  6. Dim FNum As Integer
  7. Dim FileString As String
  8. Dim SeekSize As Long
  9. Const ZipLocalFileHeadSig As Long = &H4034B50
  10. '§ ================
  11.    FileName = Right(PATH_FILENAME, Len(PATH_FILENAME) - InStrRev(PATH_FILENAME, "\"))
  12.    If Check_add_path Then
  13. '§ Path en filename
  14.       If Check_AddDriveName Then
  15.          List_Lijst.AddItem PATH_FILENAME
  16.       Else
  17.          List_Lijst.AddItem Mid(PATH_FILENAME, InStr(PATH_FILENAME, "\") + 1)
  18.       End If
  19.    Else
  20. '§ only filename
  21.       List_Lijst.AddItem FileName
  22.    End If
  23. '§ is it a ZIP file: list the contents if asked
  24.    If (Right(FileName, 4) = ".zip" Or Right(FileName, 4) = ".ZIP") And _
  25.       Check_ExploreZIP Then
  26. '§ Make sure file exists
  27.       On Error Resume Next
  28.       LENGTE = FileLen(PATH_FILENAME)
  29.       If LENGTE <> "" Then
  30. '§ Get a free file handle and open the file
  31.          FNum = FreeFile()
  32.          On Error Resume Next
  33.          Open PATH_FILENAME For Binary Access Read Lock Write As #FNum
  34. '§ Read a chunk signature
  35.             Do
  36.                On Error GoTo Error_in_File
  37.                Get #FNum, , ReadHead.zlfhSignature
  38. '§ Check for a local file header signature
  39.                If (ReadHead.zlfhSignature = ZipLocalFileHeadSig) Then
  40. '§ Ok, read the full structure
  41.                    Seek #FNum, Seek(FNum) - 4
  42.                    Get #FNum, , ReadHead
  43.                    With ReadHead
  44. '§ Get the file name
  45.                        If (.zlfhFileNameLength) Then
  46.                            FileString = Space(.zlfhFileNameLength)
  47.                            Get #FNum, , FileString
  48.                            If Mid(FileString, Len(FileString)) <> "/" And _
  49.                               FileString <> "" Then
  50.                               If Check_add_path Then
  51. '§ Path en filename
  52.                                  If Check_AddDriveName Then
  53.                                     List_Lijst.AddItem _
  54.                                        PATH_FILENAME & " ==>[ " & FileString & " ]"
  55.                                  Else
  56.                                     List_Lijst.AddItem _
  57.                                        Mid(PATH_FILENAME, InStr(PATH_FILENAME, "\") + 1) & _
  58.                                        " ==>[ " & FileString & " ]"
  59.                                  End If
  60.                               Else
  61. '§ only filename
  62.                                  List_Lijst.AddItem _
  63.                                     FileName & " ==>[ " & FileString & " ]"
  64.                                  List_Lijst.Refresh
  65.                               End If
  66.                            End If
  67. '§ No filename?
  68.                        Else
  69.                            List_Lijst.AddItem "Got file: [No name]"
  70.                        End If
  71. '§ Work out how much extra data to skip over
  72.                        SeekSize = .zlfhCompressedSize
  73.                        If (.zlfhExtraFieldLength) Then _
  74.                            SeekSize = SeekSize + .zlfhExtraFieldLength
  75.                        If (.zlfhBitFlag And &H4) Then _
  76.                            SeekSize = SeekSize + 12
  77. '§ Seek to next record
  78.                        Seek #FNum, Seek(FNum) + SeekSize
  79.                   End With
  80. '§ Increment file count
  81.                Else
  82.                    Exit Do
  83.                End If
  84.             Loop
  85.          Close #FNum
  86.       Else
  87.          MsgBox ("Error in ZIP filename: " & PATH_FILENAME)
  88.       End If
  89.    End If
  90. Exit Function
  91. Error_in_File:
  92.    MsgBox ("There is an error reading file: " & PATH_FILENAME)
  93.    List_Lijst.AddItem FileName & " ERROR READING FILE "
  94. End Function
Reply

Tags
cdrom, error, reading, trapping


Similar Visual Basic 4 / 5 / 6 bytes