Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Accessing drive A: without getting halted if drive is empty?

Status
Not open for further replies.

siearo

MIS
Aug 21, 2002
15
LK
I want to execute a program to copy all files in drive a: in to a given folder preferably by using a DOS batch file without getting halted if there is no disk in drive a:.
Eg: copy a:\*.* c:\*.* will give a "not ready reading drive a:" message and the batch file is halted there.
If this is not possible with DOS, Can anybody give me the source code of a program in Visula Basic or DOS asembler(Debug) to do the same job.
 

[tt]
Private Sub CheckADrive()

On Error GoTo CheckADriveError

Dim S As String

S = Dir("a:\")

Exit Sub
CheckADriveError:

If Err.Number = 52 Then 'Error 52 bad file name or number
MsgBox "Error Reading Drive A: Please Insert A Properly Formatted Disk!", vbOkOnly, "Error Reading Drive A:"
Exit Sub
End IF

MsgBox Err.Description

End Sub
[/tt]
 
Use the COPYFILE or FILECOPY routine in VB instead of a batch file. You can put an error routine around it report and ignore all errors
 
Yup, vb5prgrmr has it right.

Just a nit, some versions of BASIC or Basic go a little wacky if you don't turn Error Handling back off.

Some B's allow On Local Error which in theory disappears when the code module ends, this is safer but it is safer still for you to turn Error handling OFF

On Error GoTo 0
or
On Local Error GoTo 0

and put the appropriate one at the sub exit and also in the error handling exit.

It is a small pain, but otherwise you might have a bad filename somewhere else, or perhaps a missing DLL somewhere and your program might say

Error Reading Drive A: Please Insert A
Properly Formatted Disk!

Which tends to confuse users. Programmers, too.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top