Issue with Mac, Linux and windows portability with ls and sprintf commant
9 views (last 30 days)
Show older comments
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
0 Comments
Answers (2)
Sean de Wolski
on 9 Dec 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 Comment
Walter Roberson
on 9 Dec 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.
See Also
Categories
Find more on File Name Construction in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!