Read disk, directory and library name

From BeebWiki
Revision as of 19:13, 8 March 2015 by WikiSysop (talk | contribs) (1 revision)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

The following function from the FileIO library will return the name of the currently selected disk, directory or library.

   REM Return current disk (5), directory (6) or library (7) name
   REM ----------------------------------------------------------
   DEFFNgbpb(A%):X%!1=name%:CALL&FFD1:A%=name%+((1+?name%)AND((A%AND-2)=6))
   A%?(1+?A%)=13:=$(A%+1)

When calling the function:

  • FNgbpb(5) returns the disk name
  • FNgbpb(6) returns the current directory name
  • FNgbpb(7) returns the current library name

NFS always returns the names padded with spaces - 16 characters for the disk name, and 10 characters for the directory and library name.

Reading the full pathname

The following functions from the Pathname library read the full pathname for the current directory, the current library and the user's home directory.

   REM FNPath_Name - Return pathname with drive number or name if no number
   REM FNPath_Full - Returns full pathname with diskname
   REM The returned pathname can be used to select the directory with *DIR
   REM --------------------------------------------------------------------
   :
   DEFFNPath_Name:A%=6
   DEFFNPath_Full:A%=&106
   LOCAL n$,p$:REPEAT:X%!1=name%:CALL &FFD1
   ?(name%+2+?name%+?(name%+?name%+1))=13
   n$=$(name%+2+?name%):*DIR ^
   n$=LEFT$(n$,INSTR(n$+" "," ")-1)
   p$=n$+"."+p$:UNTILn$="$"ORn$="&"
   p$=LEFT$(p$,LENp$-1):OSCLI"DIR "+p$
   IFA%=6:X%!1=name%:CALL &FFD1:?(name%+1+?name%)=13:n$=$(name%+1):IFn$<>"":=":"+n$+"."+p$
   X%!1=name%:A%=5:CALL &FFD1
   ?(name%+1+?name%)=13:n$=$(name%+1)
   n$=LEFT$(n$,INSTR(n$+" "," ")-1):=":"+n$+"."+p$
   :
   :
   REM FNPath_Lib - Return library pathname
   REM ------------------------------------
   :
   DEFFNPath_Lib
   LOCAL a$,b$:a$=FNPath_Name:*DIR %
   b$=FNPath_Name:OSCLI"DIR "+a$:=b$
   :
   :
   REM FNPath_LibFull - Return full library pathname
   REM ---------------------------------------------
   :
   DEFFNPath_LibFull
   LOCAL a$,b$:a$=FNPath_Name:*DIR %
   b$=FNPath_Full:OSCLI"DIR "+a$:=b$
   :
   :
   REM FNPath_URD - Return URD pathname
   REM --------------------------------
   :
   DEFFNPath_URD
   LOCAL a$,b$:a$=FNPath_Name:*DIR &
   b$=FNPath_Name:OSCLI"DIR "+a$:=b$
   :
   :
   REM FNPath_URDFull - Return full URD pathname
   REM -----------------------------------------
   :
   DEFFNPath_URDFull
   LOCAL a$,b$:a$=FNPath_Name:*DIR &
   b$=FNPath_Full:OSCLI"DIR "+a$:=b$

This is an example of what would be returned by the functions:

  • FNPath_Name would return  :0.$.Progs.Temp
  • FNPath_Full would return  :ProgramDisk.$.Progs.Temp
  • FNPath_Lib would return  :1.$.Library
  • FNPath_LibFull would return  :UtilsDisk.$.Library
  • FNPath_URD would return  :0.$.User1
  • FNPath_URDFull would return  :MyDisk.$.User1

These functions will work on NFS, ADFS and any well behaved filing system that recognises the '^' directory. They will not work on Acorn file servers that do not recognise '^'.

Dependancies

These functions need global control blocks set up beforehand with:

   DIM ctrl% 31,name% 31:X%=ctrl%:Y%=X%DIV256

Jgharston 11:26, 27 August 2008 (BST)