Recursive directory searching for multiple file specs?
Contents
Brett's Pick this week is ... nonexistent. (Instead, here's another challenge.)
A Recursive DIR Command that Accommodates a Complex Filterspec
For a project that I'm currently working on, I want to return a directory listing of all files matching one of several specified formats. I wanted to include in my directory search, for example, all files of type 'doc', 'xml', or 'html'. I can easily select such files using MATLAB's uigetfile command:
[filename, pathname] = uigetfile({'*.doc;*.xml;*.html','Brett''s File Formats';... '*.*','All Files' },'Brett''s Search',... 'C:\Brett\Miscellaneous Documents\myFile.xml',... 'multiselect','on')
But listing those files in a dir-like format is another (more challenging) matter. Moreover, just to complicate the issue, I want to be able to specify recursive or non-recursive searching--that is, to tell MATLAB to include or exclude, respectively, subdirectories below my initial search path.
The dir command doesn't support that capability.
Rather than write my own custom directory-listing code, my first thought was to search the File Exchange to see if someone had already done so. I was not (initially) disappointed; there are several submissions that appear to do what I need the function to do. (What an amazing resource the File Exchange is!) In fact, there were so many promising files on the Exchange that I decided to get even more restrictive in my criteria. Specifically, I wanted to find a directory-searching function that:
- can search for multiple file formats;
- can search recursively or non-recursively;
- provides a command-line (non-GUI) interface;
- works "out-of-the-box" in R2012b--without requiring a lot of effort on my part;
- returns results in the same format that the dir command returns; and
- is shared under a BSD license.
Would I have any luck with these more restrictive requirements?
As it turns out, not so much. I found many files that satisfy some of my criteria, but none that satisfies them all. Armed with that knowledge, and with some insights I had gained by looking at some other contributors' code, I figured that I could either relax my criteria (some of them are "must-haves," others are just niceties), or I could write my own function. But then I had another idea: this is great fodder for a blog post! Why not challenge readers to create a function to meet those specs? (How far are you willing to go for MATLAB swag, and for recognition in the Pick-of-the-Week blog?) :)
Did I Miss Something?
First, if I overlooked (or misjudged) a particular submission, please let me know. If I agree that a file currently on the exchange meets all of the criteria listed above, I'll recognize your file publicly, apologize humbly, and send you some swag! It's quite possible that I missed something.
So Here's the Challenge
I will send some swag to the first person who shares on the File Exchange some code that meets the six criteria specified above. You can start from scratch, or you can modify an existing file--yours, or someone else's. And I will feature your submission as a Pick-of-the-Week in a future blog.
As always, I welcome your thoughts and comments.
- カテゴリ:
- Picks
コメント
コメントを残すには、ここ をクリックして MathWorks アカウントにサインインするか新しい MathWorks アカウントを作成します。