Be the first to rate this file! 6 Downloads (last 30 days) File Size: 6.42 KB File ID: #40042

Recursive directory search

by

 

28 Jan 2013 (Updated )

LS2 searches directories and shows directory listings recursively.

| Watch this File

File Information
Description

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;

Acknowledgements

Ls Mod inspired this file.

MATLAB release MATLAB 8.0 (R2012b)
Other requirements Created in R2012b. It should work in MATLAB R2010a or newer.
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Updates
15 Feb 2013

Files and directories are returned as a relative paths.

19 Feb 2013

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.

Contact us