BBC BASIC for Windows
Programming >> BBC BASIC language >> Disc drive check http://bb4w.conforums.com/index.cgi?board=language&action=display&num=1426282721 Disc drive check
Post by TheFamousCash on Mar 13th, 2015, 9:38pm
I run a program which requires to delete a file if it is on disc. Using "openup" to check if file is there produces error if drive empty as does SYS "FindFirstFile". Please could someone advise how I check if there is a disc in the drive without generating an error? Thanks.
Re: Disc drive check
Post by rtr2 on Mar 13th, 2015, 10:21pm
Please could someone advise how I check if there is a disc in the drive without generating an error?
This doesn't answer your question, but I should point out that even if such a test exists it doesn't really help. There will always be a finite time window between you performing the test and attempting to delete the file, during which the disc could have been ejected. In that (admittedly unlikely) event you're back to square one.
Getting back to the problem, are you specifically referring to floppy discs? I don't think that SYS "DeleteFile" generally does generate an error if a removable disc (e.g. CD-ROM) is missing, but floppies are an exception.
Read this Raymond Chen blog post for some background:
Re: Disc drive check
Post by TheFamousCash on Mar 16th, 2015, 02:21am
Richard, Many thanks for your response. Speaking of CDs containing programs in normal PC disc drive. I found one of your functions which works perfectly:- IFCD$="D"SYS "DeleteFile", src$+$fpt%, dst$+$fpt%, 0 TO res% IFCD$="C"SYS "CopyFile", src$+$fpt%, dst$+$fpt%, 0 TO res% However, if there is no disc in the drive, an error is generated showing "No disc is in drive". I cannot find a method to circumvent this problem. (*CD, *DIR et cetera and attempting to see a file is on disc by using OPENUP, all generate the error.) I thought I had settings which advised by email when a reply had been posted but just found your response in double-checking. Thanks, Bob. Re: Disc drive check
Post by sveinioslo on Mar 18th, 2015, 12:16pm
Maybe this proc does the trick ?
Svein
Code:
DEF PROCdeletefile(file$)
ON ERROR LOCAL : ENDPROC
OSCLI "DEL "+file$
ENDPROC
Re: Disc drive check
Post by rtr2 on Mar 18th, 2015, 1:03pm
Or, more straightforwardly (and no need for a PROC):
Code:
SYS "DeleteFile", file$
But I already suggested that to the OP, and he said he tried it, so probably the error message he is referring to is a popup window like the one you get with a missing floppy.
Richard.
Re: Disc drive check
Post by sveinioslo on Mar 18th, 2015, 9:55pm
I was hoping that the "No disc is in drive" error was trappable. Can't test it at my current location.
Svein
Re: Disc drive check
Post by TheFamousCash on Mar 19th, 2015, 12:21pm
Many thanks for assistance. I have found solution. Cycling through to discover which LT$ is actual disc drive using below PROC and checking to see if file$ present. If CDFLAG%=1 then simple OSCLI "DEL """+file$+"""" completes.
DEFPROCCHECKDISK(LT$) ON ERROR LOCAL:ENDPROC OSCLI "CD """+LT$+"""" LOCAL dir%, sh%, res% DIM dir% LOCAL 317 SYS "FindFirstFile", "*", dir% TO sh% IFsh%<>-1P%=OPENUPfile$:IFP>0CDFLAG=1:CLOSE#P% ENDPROC