help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Directory Listing in Octave -- Recursion


From: John W. Eaton
Subject: RE: Directory Listing in Octave -- Recursion
Date: Wed, 9 Dec 2009 13:25:21 -0500

On  9-Dec-2009, HALL, BENJAMIN            PW wrote:

| Here is something I found in my files...
| 
| ## Windows versions of octave come packaged with the find utility
| ## as provided by MSYS.  This is the found in the path before the
| ## Windows built-in (and worthless) find utility.  So, it turns
| ## out to be easy...
| 
| [stat,lsout] = system( sprintf("find %s -name '*.cmp'",cpath), 1, "sync"
| );
| 
| fls = cellstr( split( lsout, "\n" ) );

Here is a solution that does not require external utilties:

  function retval = rdir (d)
    ## info about D
    d_info = dir (d);
    ## list of directories in D, not including . and ..
    names = {d_info.name};
    subdirs = names([d_info.isdir]);
    subdirs = subdirs(3:end);
    ## adjust filenames to include directory info
    for j = 1:numel (d_info)
      d_info(j).name = fullfile (d, d_info(j).name);
    endfor
    retval = d_info;
    for i = 1:numel (subdirs)
      ## recurse and append results for subdirectories to the list
      d_info = rdir (fullfile (d, subdirs{i}));
      retval = [retval; d_info];
    endfor
  endfunction

However, this solution is fairly slow for large directories at least
in part because Octave's dir function is also an interpreted
function.  It might be good to convert that function to C++.

Also, this function assumes that the first two entries returned from
the dir function are "." and "..".  Is that always true on Windows
systems as well?

jwe


reply via email to

[Prev in Thread] Current Thread [Next in Thread]