MATLAB: How to use dir in subfolders

addpathdirgenpathsearch inside subfolders

I am trying to search for all the xlsx files inside a folder that have many subfolders to search from. I realize matlab does not search inside subfolders. So I tried this:
>> addpath(genpath('D:/'))
>> savepath
>> dir *.xlsx
but it is not working, please advice on what I can do. I want to make a code that works for any folder that I put inside genpath(' '). Thanks!

Best Answer

See the attached demo.