473,378 Members | 1,475 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

how to trap an error reading CDrom

Guido Geurs
767 Expert 512MB
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
Oct 12 '09 #1
0 1750

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Silvio Golubović | last post by:
I have a problem with my CDROM. It reads only original cd.
2
by: enclume42 | last post by:
Hello, I am a pure Linux guy. I wrote a Java program that is going to be used by some Windows people, and I wish the startup of the program to be as simple as possible, namely to double-click on...
10
by: Mike D | last post by:
I have a table in SQL 2000 with a composite Primary Key on coulumns Instrument_ID (int) and WeekOf (smalldatetime.) I am running asp on win 2003. I insert values using a stored procedure from...
6
by: Jim Anderson | last post by:
I'm just starting to use XML and I'm thinking of using DocBook for some documentation. I tried my first simple example from the book and I'm getting a parse error. I iniitally typed in the...
10
by: pemo | last post by:
As far as I understand it, a trap representation means something like - an uninitialised automatic variable might /implicitly/ hold a bit-pattern that, if read, *might* cause a 'trap' (I'm not...
111
by: Tonio Cartonio | last post by:
I have to read characters from stdin and save them in a string. The problem is that I don't know how much characters will be read. Francesco -- ------------------------------------- ...
3
by: Klapet | last post by:
Hi, I'm quite new in C++ programing and I want to ask, if I can handle events in simple console-like program. For example I need one loop to repeat until some key is pressed. Is it possible to...
3
by: Ognjen Bezanov | last post by:
Hello, I am trying to control a CD-ROM drive using python. The code I use is shown below.
4
by: elShazo | last post by:
I am getting this error on compile "expected unqualified-id at end of input". Here is the block of code that generates the error: /* Proxy unmountSource I/O */ /* Method unmountSource */...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.