File Copying Error

slim steve
05-21-2003, 02:16 AM
Hi,

I have a small problem with a file copying routine which I have written. The routine is supposed to list all the files in the folder on the drive L: (some 300 fiiles) and copy them to the local C: drive. It works ok until it finds more than one error (error code 53) and on finding a second error displays the error message box instead of writing it to file and closes the application.

Any ideas why this is doing this would be appreciated.

Slim



Private Sub Command1_Click()
'This section copies data from L: to c:
Dim dafeventlog As String, T As String


On Error GoTo daf_errorcode_AP003

Open "c:\logs\eventlog.txt" For Append As #1
Print #1, Date, Time, "Starting Warehousing copy to c:\whsdata"

Open "c:\daf\logs\dellno1warehousing.txt" For Output As #2
T = Dir("l:\tran320\hnature\data\*.*") 'Specify Path and get first file
Do 'loop until all files read

If T <> "" Then 'Make sure a file has been found
On Error GoTo point1
FileCopy "l:\tran320\hnature\data\" & T, "c:\whsdata\" & T 'copy the file
End If

point1:
Print #2, Date, Time, T, Err.Number, Err.Description
Err.Clear

T = Dir 'Get the next file
Loop Until T = "" 'If there is no next file exit loop

Print #1, Date, Time, "Warehousing to C:\whsdata completed"
Close #1
Close #2

Exit Sub


daf_errorcode_AP003:
Close #2
Print #1, Date, Time, "DAF Error code AP003, Error copying Data to c:\whsdata"
Close #1

End Sub

Squirm
05-21-2003, 02:38 AM
Well there are a few things. I think item 3 is particularly important:

1) When you call the Dir$() function, the *.* is not needed:
T = Dir$("l:\tran320\hnature\data\\")

2) The returned filename does not contain a leading backslash so you will need to append one:
FileCopy "l:\tran320\hnature\data\\" & T, "c:\whsdata\\" & T 'copy the file

3) Your On Error Goto point1 statement should come somewhere before your Do statement.

4) You might want to consider checking that an error has occured rather than always writing to the file:
If Err.Number Then
Print #2, Date, Time, T, Err.Number, Err.Description
Err.Clear
End If

5) If you checked the contents of T at the start of the loop, the inner If block would not be required:
On Error Goto point1

Do While Len(T)
FileCopy "l:\tran320\hnature\data\\" & T, "c:\whsdata\\" & T 'copy the file
'...
T = Dir$()
Loop

6) In your daf_errorcode_AP003 error-handling block, you probably want to skip any further errors. Add this line first:
On Error Resume Next

slim steve
05-23-2003, 04:19 AM
Hi,

Thanks for that advice, I have made those changes and it has fixed the errors that were occuring.

Slim

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum