Maxima equivalent of ls



On June 13, 2011, Ted Woollett wrote:
-----------------------
Here is a homemade ls function based
on the lisp function directory:
------------------------------------------
(%i15) ls(apath) := block ([%aL:[],%pL,%v],
             %pL : ?directory (apath),
             for %v in %pL do %aL : cons (%v,%aL),
             reverse(%aL))$
(%i16) ls ("c:/work2/line1*w.txt");
(%o16) [#pc:/work2/line1b1w.txt, #pc:/work2/line1b2w.txt,
                                 #pc:/work2/line1bw.txt, 
#pc:/work2/line1w.txt]
-----------------------------------
A version which strips off the drive and folder
information (and which is very dependent on the
hardware/software details of implimentation)
is
  dir(path)

adapted to a windows evironment:
the output looks nicest in display2d:true
case (the default):
--------------------------------------------
 (%i1) load(ls);
(%o1)                           c:/work2/ls.mac

(%i2) mypath : "c:/work2/line1*w.txt"$

(%i3) dir (mypath);
(%o3)        [line1b1w.txt, line1b2w.txt, line1bw.txt, line1w.txt]

(%i4) display2d:false$

(%i5) dir (mypath);
(%o5) [line1b1w\.txt,line1b2w\.txt,line1bw\.txt,line1w\.txt]
------------------------------------
code for dir(path) is:
----------------------------
dir(apath) := 
      block ([nstem,nsl,nrem,%aL:[],%pL,%v,%vp],
         [nstem,nsl] : stem_size (apath),     
         nrem : 3 + nstem + 2*nsl,     
         %pL : ?directory (apath),
         for %v in %pL do
            (%vp : simplode (rest(charlist (string (%v)),nrem)),
             %vp : parse_string (%vp), 
             %aL : cons (%vp,%aL)),
         reverse(%aL))$
----------------------------
which uses stem_size :
---------------------------
/* stem_size returns the list [ psl,nsl], in which
    psl is the string length of everything up to
    and including the last forward slash
    and nsl is the number of forward slashes */

stem_size (bpath) :=
   block ([%nsub,%stem],
     %nsub : 1 + slength (bpath)
            - sposition ("/",sreverse (bpath)),     
     %stem : substring (bpath,1,%nsub + 1),     
     [slength (%stem),nfsl(%stem)])$
-------------------------------------------
which uses nfsl:
----------------------------------
  /* nfsl(string) returns the number of forward
     slashes found in the given string */
     
  nfsl(%astr) := 
   block ([%n:0,%chL,%v ],
    %chL : charlist (%astr),
    for %v in %chL do
      if %v = "/" then %n : %n + 1,
    %n)$
-------------------------------------