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

Answers (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 Comment

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.

Sign in to comment.

Categories

Tags

Asked:

on 9 Dec 2013

Answered:

on 9 Dec 2013

Community Treasure Hunt

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

Start Hunting!