{"id":4381,"date":"2013-02-15T09:00:28","date_gmt":"2013-02-15T14:00:28","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/?p=4381"},"modified":"2013-02-14T19:17:58","modified_gmt":"2013-02-15T00:17:58","slug":"recursive-directory-searching-for-multiple-file-specs-revisited","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2013\/02\/15\/recursive-directory-searching-for-multiple-file-specs-revisited\/","title":{"rendered":"Recursive directory searching for multiple file specs&#8230;Revisited"},"content":{"rendered":"<div xmlns:mwsh=\"https:\/\/www.mathworks.com\/namespace\/mcode\/v1\/syntaxhighlight.dtd\" class=\"content\">\r\n   <introduction><\/introduction>\r\n   <p><a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/911\">Brett<\/a>'s Pick this week is <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/40016-recursive-directory-searching-for-multiple-file-specs\">DIR2<\/a>, by <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/120880\">Jonathan Sullivan<\/a>.\r\n   <\/p>\r\n   <p>And now...A Recursive <tt>DIR<\/tt> Command that Accommodates a Complex Filterspec!\r\n   <\/p>\r\n   <p>In my <a href=\"https:\/\/blogs.mathworks.com\/pick\/2013\/01\/25\/recursive-directory-searching-for-multiple-file-specs\/\">most recent blog post<\/a>, I commented on the fact that we don't have a ready way in MATLAB of providing a complex filter specifier in a call to <tt>DIR<\/tt>. I laid out a list of things I'd <i>like<\/i> to be able to do with <tt>DIR<\/tt>, and challenged our readers to jump in the game.\r\n   <\/p>\r\n   <p>And jump in you did!<\/p>\r\n   <p>I also promised to feature in my next Pick of the Week (i.e., this one), the first author and submission that met all of the\r\n      criteria I laid out. The submission, I wrote, should:\r\n   <\/p>\r\n   <div>\r\n      <ol>\r\n         <li>enable searching for multiple file formats;<\/li>\r\n         <li>allow recursive or non-recursive searches;<\/li>\r\n         <li>provide a command-line (non-GUI) interface;<\/li>\r\n         <li>work \"out-of-the-box\" in R2012b--without requiring a lot of effort on my (a user's) part;<\/li>\r\n         <li>return results in the same format that the <tt>dir<\/tt> command returns; and\r\n         <\/li>\r\n         <li>be shared under a BSD license.<\/li>\r\n      <\/ol>\r\n   <\/div>\r\n   <p>The ink had barely dried on my Post before I received a link from Evgeny to a file that appears to meet <i>most<\/i> of my criteria. But that file is not shared on the File Exchange. And I have the sense that if I were better at understanding\r\n      his instructions and writing my own regular expressions, Evgeny's <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/32036-dirwalk-walk-the-directory-tree\">dirwalk<\/a> could be coerced to do what I requested. For his efforts, we'll be sending Evgeny some MATLAB swag.\r\n   <\/p>\r\n   <p>Only slightly later in the afternoon, Jonathan shared his own submission to <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/40016-recursive-directory-searching-for-multiple-file-specs\">\"DIR2: Recursive Directory Searching for Multiple File Specs\"<\/a>. I was already thrilled with Jonathan's submission--he had earned this honor--when it got even better. Less than two weeks\r\n      after the challenge was issued and DIR2 was uploaded, Jonathan improved his submission by <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/mex.html\">converting it to MEX<\/a> to speed it up. And it is fast! Very nice job, Jonathan--your file does everything I requested, and is exceptionally easy\r\n      to use! For your efforts and code, an A+, a Pick-of-the-Week tag, and some cool swag coming your way!\r\n   <\/p>\r\n   <p>Before I move on: Mikko, if you can show me how to get <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/32993-ls-mod\">ls2<\/a> to do what I requested, I'll send you some swag, too. I tried, but can't seem to get the desired results.\r\n   <\/p>\r\n   <p>As always, I welcome your <a href=\"https:\/\/blogs.mathworks.com\/pick\/?p=4381#respond\">thoughts and comments<\/a>.\r\n   <\/p><script language=\"JavaScript\">\r\n<!--\r\n\r\n    function grabCode_dce86b1e241a499ba8754d27206c9058() {\r\n        \/\/ Remember the title so we can use it in the new page\r\n        title = document.title;\r\n\r\n        \/\/ Break up these strings so that their presence\r\n        \/\/ in the Javascript doesn't mess up the search for\r\n        \/\/ the MATLAB code.\r\n        t1='dce86b1e241a499ba8754d27206c9058 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' dce86b1e241a499ba8754d27206c9058';\r\n    \r\n        b=document.getElementsByTagName('body')[0];\r\n        i1=b.innerHTML.indexOf(t1)+t1.length;\r\n        i2=b.innerHTML.indexOf(t2);\r\n \r\n        code_string = b.innerHTML.substring(i1, i2);\r\n        code_string = code_string.replace(\/REPLACE_WITH_DASH_DASH\/g,'--');\r\n\r\n        \/\/ Use \/x3C\/g instead of the less-than character to avoid errors \r\n        \/\/ in the XML parser.\r\n        \/\/ Use '\\x26#60;' instead of '<' so that the XML parser\r\n        \/\/ doesn't go ahead and substitute the less-than character. \r\n        code_string = code_string.replace(\/\\x3C\/g, '\\x26#60;');\r\n\r\n        author = 'Brett Shoelson';\r\n        copyright = 'Copyright 2013 The MathWorks, Inc.';\r\n\r\n        w = window.open();\r\n        d = w.document;\r\n        d.write('<pre>\\n');\r\n        d.write(code_string);\r\n\r\n        \/\/ Add author and copyright lines at the bottom if specified.\r\n        if ((author.length > 0) || (copyright.length > 0)) {\r\n            d.writeln('');\r\n            d.writeln('%%');\r\n            if (author.length > 0) {\r\n                d.writeln('% _' + author + '_');\r\n            }\r\n            if (copyright.length > 0) {\r\n                d.writeln('% _' + copyright + '_');\r\n            }\r\n        }\r\n\r\n        d.write('<\/pre>\\n');\r\n      \r\n      d.title = title + ' (MATLAB code)';\r\n      d.close();\r\n      }   \r\n      \r\n-->\r\n<\/script><p style=\"text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray\"><br><a href=\"javascript:grabCode_dce86b1e241a499ba8754d27206c9058()\"><span style=\"font-size: x-small;        font-style: italic;\">Get \r\n            the MATLAB code \r\n            <noscript>(requires JavaScript)<\/noscript><\/span><\/a><br><br>\r\n      Published with MATLAB&reg; R2012b<br><\/p>\r\n<\/div>\r\n<!--\r\ndce86b1e241a499ba8754d27206c9058 ##### SOURCE BEGIN #####\r\n%% Recursive directory searching for multiple file specs...Revisited\r\n\r\n%% \r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/911 Brett>'s Pick this week is\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/40016-recursive-directory-searching-for-multiple-file-specs DIR2>, by\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/120880 Jonathan Sullivan>.\r\n\r\n%%\r\n% And now...A Recursive |DIR| Command that Accommodates a Complex Filterspec!\r\n%%\r\n% In my <https:\/\/blogs.mathworks.com\/pick\/2013\/01\/25\/recursive-directory-searching-for-multiple-file-specs\/ most recent blog post>,\r\n% I commented on the fact that we don't have a ready way in MATLAB of\r\n% providing a complex filter specifier in a call to |DIR|. I laid out a\r\n% list of things I'd _like_ to be able to do with |DIR|, and challenged our\r\n% readers to jump in the game.\r\n\r\n%% \r\n% And jump in you did! \r\n\r\n%%\r\n% I also promised to feature in my next Pick of the Week (i.e., this one), the first \r\n% author and submission that met all of the criteria I laid out. The submission, I wrote, \r\n% should:\r\n%\r\n% # enable searching for multiple file formats;\r\n% # allow recursive or non-recursive searches; \r\n% # provide a command-line (non-GUI) interface;\r\n% # work \"out-of-the-box\" in R2012bREPLACE_WITH_DASH_DASHwithout requiring a lot of effort on my (a user's) part;\r\n% # return results in the same format that the |dir| command returns; and\r\n% # be shared under a BSD license.\r\n%\r\n\r\n%%\r\n% The ink had barely dried on my Post before I received a link from\r\n% Evgeny to a file that appears to meet _most_ of my criteria. But that file\r\n% is not shared on the File Exchange. And I have the sense that if I were\r\n% better at understanding his instructions and writing my own regular\r\n% expressions, Evgeny's\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/32036-dirwalk-walk-the-directory-tree dirwalk> could\r\n% be coerced to do what I requested. For his efforts, we'll be sending Evgeny\r\n% some MATLAB swag.\r\n\r\n%%\r\n% Only slightly later in the afternoon, Jonathan shared his own submission to\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/40016-recursive-directory-searching-for-multiple-file-specs \"DIR2: Recursive Directory Searching for Multiple File Specs\">. \r\n% I was already thrilled with Jonathan's submissionREPLACE_WITH_DASH_DASHhe had earned this\r\n% honorREPLACE_WITH_DASH_DASHwhen it got even better. Less than two weeks after the challenge\r\n% was issued and DIR2 was uploaded, Jonathan improved his submission by \r\n% <https:\/\/www.mathworks.com\/help\/matlab\/ref\/mex.html converting it to MEX> to speed it up. And it is fast!\r\n% Very nice job, JonathanREPLACE_WITH_DASH_DASHyour file does everything I requested, and is exceptionally easy to use!\r\n% For your efforts and code, an A+,\r\n% a Pick-of-the-Week tag, and some cool swag coming your way!\r\n\r\n%%\r\n% Before I move on: Mikko, if you can show me how to get\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/32993-ls-mod ls2> to\r\n% do what I requested, I'll send you some swag, too. I tried, but can't\r\n% seem to get the desired results.\r\n\r\n%% \r\n% As always, I welcome your <https:\/\/blogs.mathworks.com\/pick\/?p=4381#respond thoughts and comments>.\r\n##### SOURCE END ##### dce86b1e241a499ba8754d27206c9058\r\n-->","protected":false},"excerpt":{"rendered":"<p>\r\n   \r\n   Brett's Pick this week is DIR2, by Jonathan Sullivan.\r\n   \r\n   And now...A Recursive DIR Command that Accommodates a Complex Filterspec!\r\n   \r\n   In my most recent blog post, I commented on... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2013\/02\/15\/recursive-directory-searching-for-multiple-file-specs-revisited\/\">read more >><\/a><\/p>","protected":false},"author":34,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[16],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/4381"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/users\/34"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/comments?post=4381"}],"version-history":[{"count":4,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/4381\/revisions"}],"predecessor-version":[{"id":4385,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/4381\/revisions\/4385"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=4381"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=4381"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=4381"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}