Zbex directory handling

From CCARH Wiki
Revision as of 14:35, 14 October 2010 by Craig (talk | contribs) (created page)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Zbex gives you two commands which relate to directories: getdir and createdir. In addition, you can read the contents of a directory by opening it as a file.

getdir

The getdir statement will provide you with the path of the current directory. There is no way with Zbex to change the current directory. The following example will open the current directory, read its contents, and display them on the screen.

              Program 
        --------------------- 
        str curdir.80,rec.80 
   
        getdir curdir 
        open [1,1] curdir 
        loop 
          getf [1] rec 
          putc ~rec 
        repeat 
        run 
                     Execution 
        ------------------------------------- 
        ** S=8, P=25, L=239, M=452 ** 
        DISP         <DIR>     7-18-95 10:12p 
        FORMATS      <DIR>     8-10-95 11:01p 
        MKSLURS      <DIR>    11-01-95 10:08p 
        SPECS        <DIR>     7-18-95 10:11p 
        COMPRESS OLD    59427  7-05-95  3:12p 
        DECOMP   OLD    26037  7-05-95  3:12p 
        BUG      Z        197  7-05-95  3:12p 
        EXPAND   Z      28179 10-08-95 12:18a 
        MAKECFT  Z      66767 10-09-95  7:22a 
               9 Files(s) 
        Ready for program 

createdir

The createdir statement lets you create a new directory. The path to the new directory must already exist (you can create it, one sub-directory at a time). Zbex does not provide you with a means of removing directories (or removing files, either). The following example will create a new directory in the current directory.

              Program 
        --------------------- 
           str newdir.80,curdir.80 
           str rec.80,temp.80 
     
           getdir curdir 
        B: 
           putc Name of new directory?  
           getc newdir 
           temp = ucs(newdir)     /* for comparing with current names 
     
           Make sure that this directory doesn't already exist 
     
           open [1,1] curdir 
           loop 
             getf [1] rec 
             if rec{1} = " "      /* no more entries in directory 
               goto A 
             end 
             if rec{18} = ">"     /* looking for sub-directories 
               if rec con " " 
                 rec = rec{1,mpt-1}   /* keep only the name 
               end 
               if rec = temp 
                 putc This directory already exists 
                 close [1]        /* must close [1] so we can open it an 
                 goto B 
               end 
             end 
           repeat 
        A: 
           close [1] 
     
           Directory doesn't exist; try to create it.  
     
           newdir = curdir // "/" // newdir 
           createdir newdir 
           putc ~newdir  created 
           run 
                     Execution 
        ------------------------------------- 
        Name of new directory?  
        specs 
        This directory already exists 
        Name of new directory?  
        rivet 
        C:\RELEASE\INTERNET/rivet created 
        Ready for program