Issue with Mac, Linux and windows portability with ls and sprintf commant

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)

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

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.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Filename Construction dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by