Issue with Mac, Linux and windows portability with ls and sprintf commant
Afficher commentaires plus anciens
Hi,
I can get this command to work fine under Mac OS but if fails to work under linux and windows:
tmplist = ls(sprintf('%s%s',datdir,'/*file*'))
I use this to make a list of files to input within a loop.
Any suggestions?
Cheers - Doug
Réponses (2)
Sean de Wolski
le 9 Déc 2013
Use filesep and pathsep instead of '/'. These will generate the appropriate separator for the path.
doc filesep
Or just use fullfile
doc fullfile
1 commentaire
Walter Roberson
le 9 Déc 2013
Use of filesep and fullfile are generally good ideas. However, using '/' as the separator will work on all three operating systems. Although you always see MS Windows use '\' instead of '/', internally it is really '/' in MS Windows.
Walter Roberson
le 9 Déc 2013
1 vote
Using dir() is more robust.
Catégories
En savoir plus sur Filename Construction dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!