Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!usc!sdd.hp.com!wuarchive!mit-eddie!bloom-beacon!eru!hagbard!sunic!news.funet.fi!funic!santra!santra!robin From: robin@niksula.hut.fi (Jarto 'Robin' Tarpio) Newsgroups: comp.sys.amiga Subject: Re: AmigaDOS from BASIC.... Message-ID: Date: 16 Dec 90 11:20:02 GMT References: <730026@hpmwngf.HP.COM> <643@cbmger.UUCP> Sender: news@santra.uucp (Cnews - USENET news system) Organization: Helsinki University of Technology, Finland Lines: 69 In-Reply-To: peterk@cbmger.UUCP's message of 14 Dec 90 16:53:35 GMT In article <643@cbmger.UUCP> peterk@cbmger.UUCP (Peter Kittel GERMANY) writes: Now, the interesting part of the program, where a List command is executed, is normally outcommented, because you have to assure one additional thing: To do things like this, you HAVE to invoke AmigaBASIC from Shell or CLI, NOT Workbench! To call DOS, AmigaBASIC needs this CLI background, else you get a real Guru. Not exactly. If you open a file for output and give it's FileHandle to the oputput in dos.library's Execute(), you can call DOS no matter where you started your program from. And open the output- file with dos.library's Open to get the FileHandle. (dos: XOpen) It's not a very good idea to read a dir by examining the output of list or dir. But it's the easiest way :-) For sporty ones: Here's how you should do it in principal: - Allocate 260 bytes for FileInfoBlock (exec:AllocMem) - Lock the dir (dos:Lock) - Examine the dir (dos:Examine) - Test if it was a dir and not a file PEEKL(FileInfoBlock+4) positive - Let's loop ! - Take the next file/dir with ExNext (dos:ExNext) - If it returned 0, it was the last one - The name starts at FileInfoBlock+8 and is null-terminated. - If PEEKL(FileInfoBlock+4) positive, it was a dir. - Back to the beg of loop ! - Clean up: - UnLock the dir (dos:UnLock) - Free the FileInfoBlock (exec:FreeMem) To start with: LIBRARY "exec.library" LIBRARY "dos.library" DECLARE FUNCTION AllocMem&() LIBRARY DECLARE FUNCTION Lock&() LIBRARY DECLARE FUNCTION Examine&() LIBRARY DECLARE FUNCTION ExNext&() LIBRARY For example: The allocation: FIB&=AllocMem&(260,65537) The lock: DirLock&=Lock&(SADD(YourDir$),1005) The examine: Success&=Examine&(DirLock&,FIB&) These are not at all detailed instructions, but it's always the hardest thing to find out the idea. Go step by step and examine, what you get. And be prepared to gurus ! If you do mistakes allocating the FIB and give FIB&=0 to Examine, the ExecBase doesn't like it at all :-) -- Best regards, Dr. Peter Kittel // E-Mail to \\ Only my personal opinions... Commodore Frankfurt, Germany \X/ {uunet|pyramid|rutgers}!cbmvax!cbmger!peterk /robin -- Jarto Tarpio StarSoft Ky, Finland ADSPE: Commercial ECO101 Helsinki University of Technology EMAIL: robin@niksula.hut.fi