Function File: filename = rfsearch (dname, fnpattern)
Function File: filename = rfsearch (dname, fnpattern, maxdepth)

Recursive File Search - search for file or filename pattern FNPATTERN starting in directory DNAME and return the first match.

  • dname, fnpattern Must be character strings and should conform to the directory name and filename requirements of your operating system.
  • maxdepth (optional) can be specified to limit the maximum search depth; the default value is 1 (search only in dname and subdirs of dname). Setting maxdepth to 0 limits the search to dname. Be careful with setting maxdepth to values > 3 or 4 as this can provoke excessive search times in densely populated directory trees. Keep in mind that rfsearch is a recursive function itself.

Output argument filename returns the relative file path of the first match, relative to DNAME, or an empty character string if no match was found.

Examples:

filename = rfsearch ("/home/guest/octave", "test.fil")
Look for file test.fil and start the search in /home/guest/octave
filename = rfsearch ("/home", "test.fil", 2)
Look for file test.fil, start the search in /home, and if needed
search subdirs of subdirs of /home

See also: dir, glob.

Package: io