How do I search for a wildcard file pattern (\**\* or /**/*) with in a directory in an OS independent way
66 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I need to search recusrsively for all the files in directory with a pattern p05 within the directory homeDirectory
I can use the following in windows elastixInputFiles = dir ([homeDirectory '\**\*p05*']);
and in mac/linux elastixInputFiles = dir ([homeDirectory '/**/*p05*']);
Is there any other cleaner way?
0 Commenti
Risposte (3)
Ameer Hamza
il 11 Mag 2018
elastixInputFiles = dir (fullfile(homeDirectory, '**', '*p05*'));
Also refer to this FEX submission for more details: https://www.mathworks.com/matlabcentral/fileexchange/1492-subdir--new-.
0 Commenti
Star Strider
il 11 Mag 2018
Use the *filesep (link) function to get the file separator for the system you are running your code on:
f = filesep;
elastixInputFiles = dir(sprintf('%s%c**%c*p05',homeDirectory,f,f));
Experiment to get the result you want.
0 Commenti
Walter Roberson
il 11 Mag 2018
You can always use / as a directory specifier on MS Windows. / is the actual internal directory specifier; \ was used for the shell level because / was already in use for command line switches at the shell level at the time that directories were designed into MS Windows.
0 Commenti
Vedere anche
Categorie
Scopri di più su File Operations in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!