{"id":8189,"date":"2016-12-16T09:00:35","date_gmt":"2016-12-16T14:00:35","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/?p=8189"},"modified":"2017-08-11T13:23:32","modified_gmt":"2017-08-11T17:23:32","slug":"glob-file-searching-in-matlab","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2016\/12\/16\/glob-file-searching-in-matlab\/","title":{"rendered":"Glob File Searching in MATLAB"},"content":{"rendered":"<div class=\"content\">\n<h3>Contents<\/h3>\n<div>\n<ul>\n<li><a href=\"#1\">Glob File Searching in MATLAB<\/a><\/li>\n<li><a href=\"#3\">What&#8217;s a Glob?<\/a><\/li>\n<li><a href=\"#4\">How does this differ from using the DIR function in MATLAB?<\/a><\/li>\n<li><a href=\"#7\">Enhance GLOB function in R2016b using the new String class.<\/a><\/li>\n<li><a href=\"#10\">Potential Alternative: Use Operating System Commands<\/a><\/li>\n<li><a href=\"#13\">Any thoughts on this entry?<\/a><\/li>\n<\/ul>\n<\/div>\n<h3>Glob File Searching in MATLAB<a name=\"1\"><\/a><\/h3>\n<p><a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/32620\">Greg&#8217;s<\/a> pick this week is <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/40149-expand-wildcards-for-files-and-directory-names\">Expand wildcards for files and directory names<\/a> by <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/2205943-peter-van-den-biggelaar\">Peter van den Biggelaar<\/a>.<\/p>\n<p>You want to list all the files in a folder, including those in subfolders. So you read the MATLAB documentation for <a title=\"https:\/\/www.mathworks.com\/help\/releases\/R2016a\/matlab\/ref\/dir.html (link no longer works)\">DIR<\/a> and <a title=\"https:\/\/www.mathworks.com\/help\/releases\/R2016a\/matlab\/ref\/ls.html (link no longer works)\">LS<\/a>.<\/p>\n<p>You find you can do name pattern matching using the <tt>'*'<\/tt> character. But you soon learn that you have to call those functions recursively in order to include the files in subfolders.<\/p>\n<p>Operating systems have commands with this ability, why not MATLAB<b>***<\/b>?<\/p>\n<p>I&#8217;m not sure I can answer the question &#8220;Why not MATLAB?&#8221;, but Peter has shared an excellent solution. It is one I have used in my own development projects.<\/p>\n<p>Here&#8217;s an example that finds all of the MATLAB-files in one of my larger projects:<\/p>\n<pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid #c8c8c8;\">glob(<span style=\"color: #a020f0;\">'C:\\X\\Project\\PMSM\\Demo\\**.m'<\/span>)<\/pre>\n<pre style=\"font-style: oblique;\">C:\\X\\Project\\PMSM\\Demo\\startDemo.m                                                                                                                     \nC:\\X\\Project\\PMSM\\Demo\\+task\\+dataDictionary\\t0_initWorkFolder.m                                                                                       \nC:\\X\\Project\\PMSM\\Demo\\+task\\+dataDictionary\\t1_openTestBench.m                                                                                        \nC:\\X\\Project\\PMSM\\Demo\\+task\\+dataDictionary\\t2_importEnums.m                                                                                          \nC:\\X\\Project\\PMSM\\Demo\\+task\\+dataDictionary\\t3_partitionData.m                                                                                        \nC:\\X\\Project\\PMSM\\Demo\\+task\\+dataDictionary\\t4_multipleDictionaries.m                                                                                 \nC:\\X\\Project\\PMSM\\Demo\\+task\\+mac2015\\t1_openTestBench.m                                                                                               \nC:\\X\\Project\\PMSM\\Demo\\+task\\+mac2015\\t2_generateCodeAndCopyToParentProject.m                                                                          \nC:\\X\\Project\\PMSM\\Demo\\+task\\+pcgF28035\\t1_openTestBench.m                                                                                             \nC:\\X\\Project\\PMSM\\Demo\\+task\\+pcgF28035\\t2_generateCodeAndCopyToParentProject.m                                                                        \n...<\/pre>\n<p><b>Note:***<\/b> As of R2016b, the <a title=\"https:\/\/www.mathworks.com\/help\/releases\/R2016b\/matlab\/ref\/dir.html (link no longer works)\">DIR<\/a> function supports recursive searches.<\/p>\n<h3>What&#8217;s a Glob?<a name=\"3\"><\/a><\/h3>\n<p>A glob is a pattern that includes wildcard characters that represent other sets of characters. The best well known is the <tt>\"*\"<\/tt> which represents any number of any characters. There&#8217;s a good definition <a href=\"https:\/\/en.wikipedia.org\/wiki\/Glob_(programming)\">here<\/a> along with some examples.<\/p>\n<h3>How does this differ from using the DIR function in MATLAB?<a name=\"4\"><\/a><\/h3>\n<p>Prior to R2016b the DIR function can only return elements found in the root of the search folder, and does not return elements found in child or subfolders.<\/p>\n<p><b>Results from DIR in R2016a<\/b><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/pick\/files\/dirResultR2016a.png\" hspace=\"5\" vspace=\"5\" \/><\/p>\n<p>Now, as of <a title=\"https:\/\/www.mathworks.com\/help\/releases\/R2016b\/matlab\/release-notes.html (link no longer works)\">R2016b<\/a>, you can use wildcard characters to perform recursive searches with the DIR function in MATLAB.<\/p>\n<pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid #c8c8c8;\">dir(<span style=\"color: #a020f0;\">'C:\\X\\Project\\PMSM\\Demo\\*\\*.m'<\/span>)<\/pre>\n<pre style=\"font-style: oblique;\">Files Found in: C:\\X\\Project\\PMSM\\Demo\\+test\n\nrunAll.m                   runOnlyPcg.m               \nrunAllForBaselineF28035.m  runShort.m                 \nrunAllForBaselineF28069.m  \n\nFiles Found in: C:\\X\\Project\\PMSM\\Demo\\Common\n\naddCommonPath.m     removeCommonPath.m  \ngetCommonPath.m     startup.m           \n...<\/pre>\n<p>However, even in R2016b, DIR doesn&#8217;t support additional glob special characters like <tt>?<\/tt> or character sets using <tt>[]<\/tt> or <tt>{}<\/tt>.<\/p>\n<pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid #c8c8c8;\"><span style=\"color: #228b22;\">% Find all MATLAB-files that start with t followed by a single character and an underscore.<\/span>\nglob(<span style=\"color: #a020f0;\">'C:\\X\\Project\\PMSM\\Demo\\**\\t?_*.m'<\/span>)\n<span style=\"color: #228b22;\">% Find all MATLAB-files that start with \"t1_\", \"t2_\", or \"t3_\"<\/span>\nglob(<span style=\"color: #a020f0;\">'C:\\X\\Project\\PMSM\\Demo\\**\\t[123]_*.m'<\/span>)<\/pre>\n<pre style=\"font-style: oblique;\">C:\\X\\Project\\PMSM\\Demo\\+task\\+dataDictionary\\t0_initWorkFolder.m               \nC:\\X\\Project\\PMSM\\Demo\\+task\\+dataDictionary\\t1_openTestBench.m                \nC:\\X\\Project\\PMSM\\Demo\\+task\\+dataDictionary\\t2_importEnums.m                  \nC:\\X\\Project\\PMSM\\Demo\\+task\\+dataDictionary\\t3_partitionData.m                \nC:\\X\\Project\\PMSM\\Demo\\+task\\+dataDictionary\\t4_multipleDictionaries.m         \nC:\\X\\Project\\PMSM\\Demo\\+task\\+mac2015\\t1_openTestBench.m                       \nC:\\X\\Project\\PMSM\\Demo\\+task\\+mac2015\\t2_generateCodeAndCopyToParentProject.m  \nC:\\X\\Project\\PMSM\\Demo\\+task\\+pcgF28035\\t1_openTestBench.m                     \nC:\\X\\Project\\PMSM\\Demo\\+task\\+pcgF28035\\t2_generateCodeAndCopyToParentProject.m\nC:\\X\\Project\\PMSM\\Demo\\+task\\+pcgF28035\\t3_loadAndPlotHwData.m                 \n...<\/pre>\n<h3>Enhance GLOB function in R2016b using the new String class.<a name=\"7\"><\/a><\/h3>\n<p>Strings have become first-class citizens of the MATLAB Language. Prior to R2016b, if you wanted to represent a set of strings, you had to use a <a title=\"https:\/\/www.mathworks.com\/help\/releases\/R2016b\/matlab\/cell-arrays.html (link no longer works)\">cell array<\/a> of <a title=\"https:\/\/www.mathworks.com\/help\/releases\/R2016a\/matlab\/characters-and-strings.html (link no longer works)\">character arrays<\/a> (see also: <a title=\"https:\/\/www.mathworks.com\/help\/releases\/R2016b\/matlab\/ref\/cellstr.html (link no longer works)\">cellstr<\/a>).<\/p>\n<p>The GLOB function returns a cellstr (a cell array of character arrays):<\/p>\n<pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid #c8c8c8;\">files = glob(<span style=\"color: #a020f0;\">'C:\\X\\Project\\PMSM\\Demo\\**.m'<\/span>);\nfiles(1:3)\nclass(files)\nclass(files{1})<\/pre>\n<pre style=\"font-style: oblique;\">ans =\n\n  3\u00d71 cell array\n\n    'C:\\X\\Project\\PMSM\\Demo\\startDemo.m'\n    'C:\\X\\Project\\PMSM\\Demo\\+task\\+dataDictionary\\t0_initWorkFolder.m'\n    'C:\\X\\Project\\PMSM\\Demo\\+task\\+dataDictionary\\t1_openTestBench.m'\n\n\n...<\/pre>\n<p>Remember you have to use the <tt>{}<\/tt> when extracting elements of the cell array.<\/p>\n<p><b>The String class to the rescue!<\/b><\/p>\n<pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid #c8c8c8;\">files = string(files)\nclass(files)<\/pre>\n<pre style=\"font-style: oblique;\">files = \n\n  1414\u00d71 string array\n\n    \"C:\\X\\Project\\PMSM\\Demo\\startDemo.m\"\n    \"C:\\X\\Project\\PMSM\\Demo\\+task\\+dataDictionary\\t0_initWorkFolder.m\"\n    \"C:\\X\\Project\\PMSM\\Demo\\+task\\+dataDictionary\\t1_openTestBench.m\"\n    \"C:\\X\\Project\\PMSM\\Demo\\+task\\+dataDictionary\\t2_importEnums.m\"\n    \"C:\\X\\Project\\PMSM\\Demo\\+task\\+dataDictionary\\t3_partitionData.m\"\n...<\/pre>\n<p>My favorite feature of the <a title=\"https:\/\/www.mathworks.com\/help\/releases\/R2016b\/matlab\/ref\/string.html (link no longer works)\">STRING<\/a> function is it can convert a cell array of character arrays to an array of Strings.<\/p>\n<p>Now you can start applying common string methods like <a title=\"https:\/\/www.mathworks.com\/help\/releases\/R2016b\/matlab\/ref\/contains.html (link no longer works)\">contains<\/a>, <a title=\"https:\/\/www.mathworks.com\/help\/releases\/R2016b\/matlab\/ref\/endswith.html (link no longer works)\">endsWith<\/a>, <a title=\"https:\/\/www.mathworks.com\/help\/releases\/R2016b\/matlab\/ref\/startswith.html (link no longer works)\">beginsWith<\/a>, <a title=\"https:\/\/www.mathworks.com\/help\/releases\/R2016b\/matlab\/ref\/extractbetween.html (link no longer works)\">extractBetween<\/a>, <a title=\"https:\/\/www.mathworks.com\/help\/releases\/R2016b\/matlab\/characters-and-strings.html (link no longer works)\">etc<\/a> to filter and analyze the result<\/p>\n<pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid #c8c8c8;\">hasF28035 = contains(files, <span style=\"color: #a020f0;\">'F28035'<\/span>);\nfiles(hasF28035)<\/pre>\n<pre style=\"font-style: oblique;\">ans = \n\n  59\u00d71 string array\n\n    \"C:\\X\\Project\\PMSM\\Demo\\+task\\+pcgF28035\\t1_openTestBench.m\"\n    \"C:\\X\\Project\\PMSM\\Demo\\+task\\+pcgF28035\\t2_generateCodeAndCopyToParent...\"\n    \"C:\\X\\Project\\PMSM\\Demo\\+task\\+pcgF28035\\t3_loadAndPlotHwData.m\"\n    \"C:\\X\\Project\\PMSM\\Demo\\+task\\+pcgF28035\\t4_openFloatingPointTestBench.m\"\n    \"C:\\X\\Project\\PMSM\\Demo\\+task\\+prototypeF28035\\t1_openTestBench.m\"\n...<\/pre>\n<h3>Potential Alternative: Use Operating System Commands<a name=\"10\"><\/a><\/h3>\n<p>This doesn&#8217;t necessarily reproduce all of the functionality that the GLOB function provides. But it is a mechanism that I have used to perform similar functions to GLOB.<\/p>\n<p>You can apply operating system commands from MATLAB using the <a title=\"https:\/\/www.mathworks.com\/help\/releases\/R2016b\/matlab\/ref\/system.html (link no longer works)\">SYSTEM<\/a> function. On Windows systems you can perform a recursive <a href=\"http:\/\/www.computerhope.com\/dirhlp.htm\">directory search<\/a> with the following example.<\/p>\n<pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid #c8c8c8;\">[~, files] = system(<span style=\"color: #a020f0;\">'dir \/s\/B C:\\X\\Project\\PMSM\\Demo\\*.m'<\/span>)<\/pre>\n<pre style=\"font-style: oblique;\">files =\n\nC:\\X\\Project\\PMSM\\Demo\\startDemo.m\nC:\\X\\Project\\PMSM\\Demo\\+task\\+dataDictionary\\t0_initWorkFolder.m\nC:\\X\\Project\\PMSM\\Demo\\+task\\+dataDictionary\\t1_openTestBench.m\nC:\\X\\Project\\PMSM\\Demo\\+task\\+dataDictionary\\t2_importEnums.m\nC:\\X\\Project\\PMSM\\Demo\\+task\\+dataDictionary\\t3_partitionData.m\nC:\\X\\Project\\PMSM\\Demo\\+task\\+dataDictionary\\t4_multipleDictionaries.m\nC:\\X\\Project\\PMSM\\Demo\\+task\\+mac2015\\t1_openTestBench.m\n...<\/pre>\n<p>The variable <tt>files<\/tt> is a single character array<\/p>\n<pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid #c8c8c8;\">s = size(files)\nc = class(files)<\/pre>\n<pre style=\"font-style: oblique;\">s =\n\n           1      129792\n\n\nc =\n\nchar\n\n<\/pre>\n<p>You can split this using the <a title=\"https:\/\/www.mathworks.com\/help\/releases\/R2016b\/matlab\/ref\/strsplit.html (link no longer works)\">STRSPLIT<\/a> function<\/p>\n<pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid #c8c8c8;\">files = strsplit(string(files))'<\/pre>\n<pre style=\"font-style: oblique;\">files = \n\n  1513\u00d71 string array\n\n    \"C:\\X\\Project\\PMSM\\Demo\\startDemo.m\"\n    \"C:\\X\\Project\\PMSM\\Demo\\+task\\+dataDictionary\\t0_initWorkFolder.m\"\n    \"C:\\X\\Project\\PMSM\\Demo\\+task\\+dataDictionary\\t1_openTestBench.m\"\n    \"C:\\X\\Project\\PMSM\\Demo\\+task\\+dataDictionary\\t2_importEnums.m\"\n    \"C:\\X\\Project\\PMSM\\Demo\\+task\\+dataDictionary\\t3_partitionData.m\"\n...<\/pre>\n<h3>Any thoughts on this entry?<a name=\"13\"><\/a><\/h3>\n<p>Let us know <a href=\"https:\/\/blogs.mathworks.com\/pick\/?p=8189#respond\">here<\/a>.<\/p>\n<p><script>\/\/ <![CDATA[\nfunction grabCode_3410706ed48847e88da24c2b123b7e67() {\n        \/\/ Remember the title so we can use it in the new page\n        title = document.title;\n\n        \/\/ Break up these strings so that their presence\n        \/\/ in the Javascript doesn't mess up the search for\n        \/\/ the MATLAB code.\n        t1='3410706ed48847e88da24c2b123b7e67 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 3410706ed48847e88da24c2b123b7e67';\n    \n        b=document.getElementsByTagName('body')[0];\n        i1=b.innerHTML.indexOf(t1)+t1.length;\n        i2=b.innerHTML.indexOf(t2);\n \n        code_string = b.innerHTML.substring(i1, i2);\n        code_string = code_string.replace(\/REPLACE_WITH_DASH_DASH\/g,'--');\n\n        \/\/ Use \/x3C\/g instead of the less-than character to avoid errors \n        \/\/ in the XML parser.\n        \/\/ Use '\\x26#60;' instead of '<' so that the XML parser\n        \/\/ doesn't go ahead and substitute the less-than character. \n        code_string = code_string.replace(\/\\x3C\/g, '\\x26#60;');\n\n        author = 'Greg Wolff';\n        copyright = 'Copyright 2016 The MathWorks, Inc.';\n\n        w = window.open();\n        d = w.document;\n        d.write('\n\n\n\n<pre>\\n');\n        d.write(code_string);\n\n        \/\/ Add author and copyright lines at the bottom if specified.\n        if ((author.length > 0) || (copyright.length > 0)) {\n            d.writeln('');\n            d.writeln('%%');\n            if (author.length > 0) {\n                d.writeln('% _' + author + '_');\n            }\n            if (copyright.length > 0) {\n                d.writeln('% _' + copyright + '_');\n            }\n        }\n\n        d.write('<\/pre>\n\n\n\n\n\\n');\n      \n      d.title = title + ' (MATLAB code)';\n      d.close();\n      }\n\/\/ ]]><\/script><\/p>\n<p style=\"text-align: right; font-size: xx-small; font-weight: lighter; font-style: italic; color: gray;\">\n<a><span style=\"font-size: x-small; font-style: italic;\">Get<br \/>\nthe MATLAB code<br \/>\n<noscript>(requires JavaScript)<\/noscript><\/span><\/a><\/p>\n<p>Published with MATLAB\u00ae 9.1<\/p>\n<\/div>\n<p><!--\n3410706ed48847e88da24c2b123b7e67 ##### SOURCE BEGIN #####\n%% Glob File Searching in MATLAB\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/32620 Greg's>\n% pick this week is <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/40149-expand-wildcards-for-files-and-directory-names % Expand wildcards for files and directory names> by <https:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/2205943-peter-van-den-biggelaar % Peter van den Biggelaar>.\n%\n% You want to list all the files in a folder, including those in subfolders.\n% So you read the MATLAB documentation for <https:\/\/www.mathworks.com\/help\/releases\/R2016a\/matlab\/ref\/dir.html % DIR> and <https:\/\/www.mathworks.com\/help\/releases\/R2016a\/matlab\/ref\/ls.html % LS>.\n%\n% You find you can do name pattern matching using the |'*'| character. But\n% you soon learn that you have to call those functions recursively in order to\n% include the files in subfolders.\n%\n% Operating systems have commands with this ability, why not MATLAB***?\n%\n% I'm not sure I can answer the question \"Why not MATLAB?\", but Peter has\n% shared an excellent solution. It is one I have used in my own development projects.\n%\n% Here's an example that finds all of the MATLAB-files in one of my larger\n% projects:\n\nglob('C:\\X\\Project\\PMSM\\Demo\\**.m')\n%%\n%\n%\n% ** Note:* As of <https:\/\/www.mathworks.com\/help\/releases\/R2016b\/matlab\/release-notes.html?rntext=dir&startrelease=R2016b&endrelease=R2016b&category=Language+and+Programming&groupby=release&sortby=descending&searchHighlight=dir % R2016b>, the <https:\/\/www.mathworks.com\/help\/releases\/R2016b\/matlab\/ref\/dir.html % DIR> function supports recursive searches.\n%% What's a Glob?\n% A glob is a pattern that includes wildcard characters that represent other\n% sets of characters. The best well known is the |\"*\"| which represents any number\n% of any characters. There's a good definition <https:\/\/en.wikipedia.org\/wiki\/Glob_(programming) % here> along with some examples.\n%% How does this differ from using the DIR function in MATLAB?\n% Prior to R2016b the DIR function can only return elements found in the root\n% of the search folder, and does not return elements found in child or subfolders.\n%\n% *Results from DIR in R2016a*\n%\n% <<dirResultR2016a.png>>\n%\n% Now, as of <https:\/\/www.mathworks.com\/help\/releases\/R2016b\/matlab\/release-notes.html % R2016b>, you can use wildcard characters to perform recursive searches with\n% the DIR function in MATLAB.\n\ndir('C:\\X\\Project\\PMSM\\Demo\\*\\*.m')\n%%\n%\n%\n% However, even in R2016b, DIR doesn't support additional glob special characters\n% like |?| or character sets using |[]| or |{}|.\n \n% Find all MATLAB-files that start with t followed by a single character and an underscore.\nglob('C:\\X\\Project\\PMSM\\Demo\\**\\t?_*.m')\n% Find all MATLAB-files that start with \"t1_\", \"t2_\", or \"t3_\"\nglob('C:\\X\\Project\\PMSM\\Demo\\**\\t[123]_*.m')\n\n%%\n%\n%\n%\n%% Enhance GLOB function in R2016b using the new String class.\n% Strings have become first-class citizens of the MATLAB Language.  Prior to\n% R2016b, if you wanted to represent a set of strings, you had to use a <https:\/\/www.mathworks.com\/help\/releases\/R2016b\/matlab\/cell-arrays.html % cell array> of <https:\/\/www.mathworks.com\/help\/releases\/R2016a\/matlab\/characters-and-strings.html % character arrays> (see also: <https:\/\/www.mathworks.com\/help\/releases\/R2016b\/matlab\/ref\/cellstr.html % cellstr>).\n%\n% The GLOB function returns a cellstr (a cell array of character arrays):\n\nfiles = glob('C:\\X\\Project\\PMSM\\Demo\\**.m');\nfiles(1:3)\nclass(files)\nclass(files{1})\n%%\n% Remember you have to use the |{}| when extracting elements of the cell\n% array.\n%\n% *The String class to the rescue!*\n\nfiles = string(files)\nclass(files)\n%%\n% My favorite feature of the <https:\/\/www.mathworks.com\/help\/releases\/R2016b\/matlab\/ref\/string.html % STRING> function is it can convert a cell array of character arrays to an array\n% of Strings.\n%\n% Now you can start applying common string methods like <https:\/\/www.mathworks.com\/help\/releases\/R2016b\/matlab\/ref\/contains.html % contains>, <https:\/\/www.mathworks.com\/help\/releases\/R2016b\/matlab\/ref\/endswith.html % endsWith>, <https:\/\/www.mathworks.com\/help\/releases\/R2016b\/matlab\/ref\/startswith.html % beginsWith>, <https:\/\/www.mathworks.com\/help\/releases\/R2016b\/matlab\/ref\/extractbetween.html % extractBetween>, <https:\/\/www.mathworks.com\/help\/releases\/R2016b\/matlab\/characters-and-strings.html % etc> to filter an analyze the result\n\nhasF28035 = contains(files, 'F28035');\nfiles(hasF28035)\n%% Potential Alternative: Use Operating System Commands\n% This doesn't necessarily reproduce all of the functionality that the GLOB\n% function provides. But it is a mechanism that I have used to perform similar\n% functions to GLOB.\n%\n% You can apply operating system commands from MATLAB using the <https:\/\/www.mathworks.com\/help\/releases\/R2016b\/matlab\/ref\/system.html % SYSTEM> function. On Windows systems you can perform a recursive <http:\/\/www.computerhope.com\/dirhlp.htm % directory search> with the following example.\n\n[~, files] = system('dir \/s\/B C:\\X\\Project\\PMSM\\Demo\\*.m')\n%%\n% The variable files is a single character array\n\ns = size(files)\nc = class(files)\n%%\n% You can split this using the <https:\/\/www.mathworks.com\/help\/releases\/R2016b\/matlab\/ref\/strsplit.html % STRSPLIT> function\n\nfiles = strsplit(string(files))'\n%% Any thoughts on this entry?\n% Let us know <https:\/\/blogs.mathworks.com\/pick\/ here>.\n##### SOURCE END ##### 3410706ed48847e88da24c2b123b7e67\n--><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"https:\/\/blogs.mathworks.com\/pick\/files\/dirResultR2016a.png\" onError=\"this.style.display ='none';\" \/><\/div>\n<p>\nContents<\/p>\n<p>Glob File Searching in MATLAB<br \/>\nWhat&#8217;s a Glob?<br \/>\nHow does this differ from using the DIR function in MATLAB?<br \/>\nEnhance GLOB function in R2016b using the new String class.<br \/>\nPotential&#8230; <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2016\/12\/16\/glob-file-searching-in-matlab\/\">read more >><\/a><\/p>\n","protected":false},"author":36,"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\/8189"}],"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\/36"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/comments?post=8189"}],"version-history":[{"count":11,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/8189\/revisions"}],"predecessor-version":[{"id":8808,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/8189\/revisions\/8808"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=8189"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=8189"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=8189"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}