How can I fix Error using files=dir command

7 views (last 30 days)
I upgraded MATLAB 2014 to 2018.
When I run the code, I get an error . please advise how ot fix this error.
This code (makeMaxProjections) helps me to run all the image files (either TIF or czi) in that directory.
>> makeMaxProjections('*', '.czi')
Error using dir
Characters adjacent to a ** wildcard must be file separators.
Error in makeMaxProjections (line 28)
files=dir(['*' fileString '*' ending]);
Please help me to fix the line 28 to run this cod ein 2018 version.
files=dir(['*' fileString '*' ending]);

Answers (3)

Steven Lord
Steven Lord on 16 Nov 2018
In release R2016b we enhanced dir to be able to search recursively if the filename included two asterisks adjacent to one another. I suspect fileString is empty (or begins and/or ends with an asterisk) on that line of code. In that case, you'll probably want to modify your code to take advantage of this functionality as shown in the "Find Files in Subfolders" example on the dir documentation page.

Thomas Jacob
Thomas Jacob on 17 Nov 2018
I changed the code to
files=dir([fileString, ending]);
the error is now fixed!
Thanks!

Image Analyst
Image Analyst on 17 Nov 2018
Try this:
% Make sure ending starts with a dot.
if ending(1) ~= '.'
ending = ['.', ending]
end
if isempty(fileString)
filePattern = sprintf('*%s', ending)
else
filePattern = sprintf('*%s*%s', fileString, ending)
end
files=dir(filePattern)

Categories

Find more on File Operations in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!