Back to home page

DOS ain't dead

Forum index page

Log in | Register

Back to the forum
Board view  Mix view

Good way to check if file already opened? (GW-BASIC porting) (Developers)

posted by Laaca Homepage, Czech republic, 02.02.2021, 22:18

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:

Back to the forum
Board view  Mix view
22049 Postings in 2034 Threads, 396 registered users, 177 users online (0 registered, 177 guests)
DOS ain't dead | Admin contact
RSS Feed
powered by my little forum