Recursive directory search

LS2 searches directories and shows directory listings recursively.
591 Downloads
Updated 19 Feb 2013

View License

LS2 has a command-line interface and it allows user to perform different kinds of listings or searches.

IN:
path1, path2,...pathN - directories to include in a seach [default: cwd]
-h, --help - show helpmessage
-H, --hidden - show hidden files [default: off]
-fd DATE,
--filedate=DATE - filedate filter
All the files less than a specified date will be filtered. You can reverse the filtering direction by placing the '>' mark in front of the DATE. In this case the program will filter all the files larger than a specified value. You must define the date in a format dd.mm.yyyy.
-fs SIZE,
--filesize=SIZE - filesize filter
All the files less than a specified size will be filtered.You can reverse the filtering direction by placing the > mark in front of the SIZE. In this case the program will filter all the files larger than a specified value. You can also speficy the unit for the file size. Possible units are B, KB, MB and GB.
-gd N,
--getdirectory=N - pick a directory from the dialog. You can define the number of directories you would like to include in a search by specifing the N value.
-m, --modified - show last modified date/time [default: off]
-o ORDER,
--order=ORDER - order search by name, n, modified, m, size, s [default: name]
-r, --recursive - recurse into subdirectories [default: off]
-s, --sizes - show sizes [default: off]
-S SEARCHTEXT,
--search=SEARCHTEXT - search specific files
When searching a particular file(s), you can define a search text in a form of str*, *str and str. Where str is a string
which will be contained in a file's name. It's possible to use the wildcard character "*" at the end of a string or at the beginning of a string. If the asterisk operator is used at the end of string, a file name is assumed to start with a specified string. Consistently, if the asterisk operator is used at the beginning of a string, a file name is assumed to end with a specified string. On the other hand a mere string without the asterisk operator is searched
throughout the file name. The search is
done based on case-insensitivity. All the
matched files will be highlighted in red.
-su, --suppress - suppress printing [default: off]
LS2 class offers two public methods getListingData and doSearch.
getListingData method returns results from the search in a structure
array. This structure encompasses fields which are name, date, bytes, isdir and datenum. The name field consists of directory and file names. Directories and files are represented as a relative paths to the given input directory.
doSearch method runs a search. It resets all the properties before performing the search.

Examples:
ls2('-m','-s')
ls2('-m','-s','--hidden','D:\data\...')
ls2('D:\data\...','D:\data\...','-m','-s','-r','-o s')
ls2('-gd 2','-s','-m','-o s')
ls2('--getdirectory=2','-s','-m','-order=m')
ls2('-gd','-s','-m','-fs 5 kb','-o s')
ls2('-gd','-s','-m','--filedate=>21.09.2011','-o s')
ls2('-gd','-s','-m','-fd >21.09.2011','-fs 15 kb','-o s','-r')
ls2('-gd 2','-s','-m','-o s','--search=*.pdf *.html *.xlsx')

lsObj = ls2('-r','-su','-gd','-S *.m')
data1 = lsObj.getListingData;
files = {data(~[data.isdir]).name};
lsObj.doSearch('-r','-su','-gd','-S *.cpp *.h make*')
data2 = lsObj.getListingData;

Cite As

Mikko Leppänen (2024). Recursive directory search (https://www.mathworks.com/matlabcentral/fileexchange/40042-recursive-directory-search), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2012b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
Find more on File Operations in Help Center and MATLAB Answers
Acknowledgements

Inspired by: ls_mod

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Version Published Release Notes
1.2.0.0

Directories are excluded from the output structure array when searching specific file specs and/or enabling file size/date filter. This will speed up the search process ~2x.

1.1.0.0

Files and directories are returned as a relative paths.

1.0.0.0