Re: Robust code?
- From: "Kevin Provance" <casey@xxxxxxxxxxx>
- Date: Fri, 30 Mar 2007 13:54:12 -0400
Logically, it would seem that perhaps the file operation was completed but
something happened in the logging process and the log was never written. I
see you have an error trap tp cover that...so perhaps whatever prevented the
logging of the action also prevented the logging of the error? How many
times has this happened thus far? Have you actually seen it fail (code
stepping, etc.?) If it's happening frequently, one thing I've done to find
bugs such as these is to run the whole project in the IDE, sometimes
overnight and leave the error trapping off. So when the phantom error
occurs, VB would kick it right back to me on screen at the bad line. Also,
I am ssuming this is XP of some flavour? Or have you playing with Vista?
Also, and this is just personal preference, take it or leave it...but I
stopped using Dir to determine if a file or folder exists a long time ago.
It acted flaky (as in, didn't work) one time to many, and I went to an API
solution which has never failed me (::knocks on wood::). With that in mind
I also use Shell API to move, copy, rename and delete files. But like I
said, I am an API junky. ;-)
- Kev
"Saga" <antiSpam@xxxxxxxxxxxxx> wrote in message
news:%230JJByucHHA.3484@xxxxxxxxxxxxxxxxxxxxxxx
| Hi all,
|
| There is an application that checks every 30 seconds to determine whether
any new
| files have been copied to a folder and is interested in two types of
files: TXT and GZ.
| When it finds these it copies them to a work folder and after that it
moves them to a
| backup folder and lastly logging this activity. After that the app scans
the work folder
| for any files and processes them accordingly, also logging this process.
This app has
| been live for about 2 years without major incident (related to this
matter), but yesterday
| a file was found in the backup folder that was not processed and not
logged at all.
|
| This is unusual, so I analyzed the code which in part I present below and
found
| nothing gapingly wrong. I see no way that it could have moved the file
into the backup
| folder without loggng the action. Frankly, I need another set of eyes to
have a look at it
| and tell me if its logic flow could permit the anomaly mentioned above. I
will appreciate
| any feedback.
|
| Regards
| Saga
|
|
|
| ' strFullname - folder where files are located at
| ' strBackupSubFolder - backup folder path
| ' intLogFH - log file file number.
|
| 'See if the file folder exists. If not, no
| 'work is done.
| If Dir$(strFullName, vbDirectory) <> "" Then
| 'Get the initial file.
| strFile = Dir$(strFullName & "\*.*")
|
| 'Test for errors inline.
| On Error Resume Next
|
| Do While strFile <> ""
| 'TXT - The bare database.txt file
| 'GZ - Database.txt in gz file
|
| If UCase(Right$(strFile, 4)) = ".TXT" Or _
| UCase(Right$(strFile, 3)) = ".GZ" Then
|
| 'Copy it to the work folder.
| FileCopy strFullName & "\" & strFile, _
| App.Path & "\Work\" & strFile
|
| 'If error then leave file alone and wait till
| 'next time to try and copy it again.
| If Err.Number = 0 Then
| 'No error on copy, move file to backup folder.
| 'Build name for backup file.
| strNewName = Left$(strFile, InStrRev(strFile, ".")) & "bak"
|
| 'Move file to backup folder if defined, if not
| 'defined then just delete file.
| If Len(Dir$(strFullName & "\" & strBackupSubFolder,
vbDirectory)) > 0 Then
|
| 'Make sure the bak file does not exist, if it does, delete
it.
| If Len(Dir$(strFullName & "\" & strBackupSubFolder & "\" &
strNewName)) > 0 Then
| Kill strFullName & "\" & strBackupSubFolder & "\" &
strNewName
| End If
|
| 'Move file.
| Name strFullName & "\" & strFile As _
| strFullName & "\" & strBackupSubFolder & "\" &
strNewName
|
| Else
| 'Backup folder not defined, just delete file.
| Kill strFullName & "\" & strFile
| End If
|
| 'Log activity.
| Print #intLogFH, "Moving " & strFile & " to work folder"
|
| 'Since I modified the file structure, I need to reinitialize
the
| 'directory scan with a new Dir() instruction.
| strFile = Dir$(strFullName & "\*.*")
|
|
| Else
| 'Bad - log error.
| strErr = "Error copying " & strFile & ": (" & Err.Number &
")" & Err.Description
| Print #intLogFH, strErr
|
| Err.Clear
|
| 'No folder alteration was done, get next file.
| strFile = Dir$()
| End If
|
|
| Else
| 'Unrelated file, skip, get next file.
| strFile = Dir$()
| End If
|
| Loop
|
| 'Reestablish normal error checking.
| On Error GoTo errhand
|
| End If
|
|
|
.
- Follow-Ups:
- Re: Robust code?
- From: Saga
- Re: Robust code?
- References:
- Robust code?
- From: Saga
- Robust code?
- Prev by Date: Re: vb6 -v- Net!
- Next by Date: Re: vb6 -v- Net!
- Previous by thread: Robust code?
- Next by thread: Re: Robust code?
- Index(es):
Relevant Pages
|
Loading