New to coding - Error /.DS_Store (Name is nonexistent or not a directory) on MacBook
9 views (last 30 days)
Show older comments
Hi all,
I am new to coding with zero prior experience. I have copied an existing code from a PC (expecting it to be plug and play) and it throws up an error saying "x/.DS_Store (Name is nonexistent or not a directory)". I reckon this should be a quick fix for someone who works with Matlab on macs. Please help me to get rid of this problem!
Cheers,
AS
9 Comments
Stephen23
on 24 Jun 2022
Edited: Stephen23
on 24 Jun 2022
"cd(foldername);"
Someone wrote slow fragile code that:
- uses CD() when using absolute/relative filenames is more robust and more efficient,
- iterates over everything that DIR() returns, without using a suitable match string or filtering the results (e.g. based on the ISDIR property), i.e. fragile/buggy code (as your experience using it demonstrates).
Basically you should NOT learn from this code.
Accepted Answer
Image Analyst
on 24 Jun 2022
I think that's just some sort of system bookkeeping file on Macs. It's not a file you'd ever want to process in any way so just skip it in your loop:
folder = pwd; % wherever you want
fileList = dir(fullfile(folder, '*.*'))]
% If you want all the names put one cell array:
allFileNames = fullfile({fileList.folder}, {fileList.name})'
% Now files are listed in the order you called dir().
% If you want the list sorted alphabetically:
allFileNames = sort(allFileNames)
for k = 1 : numel(allFileNames)
thisFileName = allFileNames{k};
if contains(thisFileName, 'DS_Store')
% Skip this kind of file.
continue;
end
% If it gets here, the file is good so process it.
end
5 Comments
Image Analyst
on 4 Jul 2022
OK since my solution of skipping that particular file worked, could you please click the "Accept this answer" link? Thanks in advance. 🙂
More Answers (0)
See Also
Categories
Find more on File Operations 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!