How do I search for a wildcard file pattern (\**\* or /**/*) with in a directory in an OS independent way
66 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (3)
Ameer Hamza
le 11 Mai 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 commentaires
Star Strider
le 11 Mai 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 commentaires
Walter Roberson
le 11 Mai 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 commentaires
Voir également
Catégories
En savoir plus sur File Operations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!