Check that file exists: Difference between revisions

Line 442:
`Abdu'l-Bahá.txt does not exist</pre>
 
 
==={{header|Commodore BASIC}}===
Try a file, then check the error status of the disk drive. "62" is the "File not found" error. The trick is to open the file without specifying the file type (PRG, SEQ, REL, etc.) and the Read/Write mode in the OPEN statement, otherwise you will end up with error 64 File Type Mismatch.
<lang gwbasic>10 REM CHECK FILE EXISTS
15 ER=0:EM$="":MSG$="FILE EXISTS."
20 PRINT CHR$(147);:REM CLEAR SCREEN
30 FI$="":INPUT "ENTER FILENAME TO CHECK";FI$:PRINT
35 IF FI$="" THEN PRINT "ABORTED.":END
40 OPEN 8,8,8,FI$
50 GOSUB 1000:REM FETCH ERROR STATUS FROM DRIVE: 0=OK, 62=FILE NOT FOUND
55 REM COMPARE ERROR NUMBER
60 IF ER<>0 THEN MSG$="I/O ERROR:"+STR$(ER)+" "+EM$
70 IF ER=62 THEN MSG$="'"+FI$+"' IS NOT HERE."
80 REM DO THINGS WITH FILE...
100 CLOSE 8
110 PRINT MSG$
120 PRINT:GOTO 30:REM REPEAT UNTIL EMPTY FILENAME IS ENTERED
1000 REM CHECK ERROR CHANNEL FOR STATUS OF LAST DISK OPERATION
1010 OPEN 15,8,15
1015 REM GET ERROR CODE, ERROR MESSAGE, TRACK, SECTOR
1020 INPUT#15,ER,EM$,T,S
1030 CLOSE 15
1040 RETURN</lang>
 
{{Out}}<pre>ENTER FILENAME TO CHECK? INDEX.TXT
FILE EXISTS.
 
ENTER FILENAME TO CHECK? NOFILE.DOC
 
'NOFILE.DOC' IS NOT HERE.</pre>
 
=={{header|Batch File}}==
113

edits