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: Stefan Pofahl
Subject: Re: Directory Listing in Octave -- Recursion
Date: Wed, 17 Jun 2020 15:53:12 +0200

I found also a solution here:
https://www.mathworks.com/matlabcentral/fileexchange/19550-recursive-directory-listing
rdir by Gus Brow.
I have not tried another variant:
https://www.mathworks.com/matlabcentral/fileexchange/47125-rdir-m
by  Core.

I modified the one from Gus Browto make it compatible to Octave.
Matlab does not need this function any longer, as the "**" syntax is since Matlab v2016b integrated into dir().

Attached the version that I use.

Regards,

Stefan

Am Mi., 9. Dez. 2009 um 19:33 Uhr schrieb John W. Eaton <jwe@octave.org>:
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
_______________________________________________
Help-octave mailing list
Help-octave@octave.org
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave


--
Stefan Pofahl
Zollgasse 5
8020 Graz
Österreich
Tel.: +43 (316) 33 2001

Attachment: MyLib_rdir.m
Description: Binary data


reply via email to

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