Good way to check if file already opened? (GW-BASIC porting) (Developers)
You can use the exclusive file access. You probable open files via INT21h/AX=3Dh
If you can control all access to files you can set the AL register to 12h
(exclusive file access in R/W mode)
The next attempts for accessing this file will generate DOS errors 5h or 56h
Implementation in pascal:
var f1,f2:file;
i:integer;
s:string;
begin
{$I-}
Filemode:=$12;
write('Enter filename for open: ');
readln(s);
Assign(f1,s);
Reset(f1);
if IOresult<>0 then begin writeln('Error in opening file.');Halt(2);end;
write('Again enter filename (the same one or other one) for open: ');
readln(s);
Assign(f2,s);
Reset(f2);
i:=IOresult;
if i=5 then writeln('The file was already opened before!') else
if i=0 then writeln('Both files was opened OK.')
else writeln('The first file was opened but the second file not.');
end.
---
DOS-u-akbar!
Complete thread:
- Good way to check if file already opened? (GW-BASIC porting) - tkchia, 02.02.2021, 14:35 (Developers)
- Good way to check if file already opened? (GW-BASIC porting) - Ringding, 02.02.2021, 20:57
- Good way to check if file already opened? (GW-BASIC porting) - tkchia, 04.02.2021, 09:05
- Good way to check if file already opened? (GW-BASIC porting) - rr, 02.02.2021, 21:16
- Good way to check if file already opened? (GW-BASIC porting) - Laaca, 02.02.2021, 22:18
- Good way to check if file already opened? (GW-BASIC porting) - tkchia, 13.02.2021, 19:23
- Good way to check if file already opened? (GW-BASIC porting) - Ringding, 02.02.2021, 20:57