New to coding - Error /.DS_Store (Name is nonexistent or not a directory) on MacBook

조회 수: 9 (최근 30일)
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
Stephen23
Stephen23 2022년 6월 24일
편집: Stephen23 2022년 6월 24일
"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.
AS
AS 2022년 7월 4일
Hi all, the code now works after asking it to ignore the "DS_store" file. A colleage helped me integrate that into the existing code. Many thanks!

댓글을 달려면 로그인하십시오.

채택된 답변

Image Analyst
Image Analyst 2022년 6월 24일
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
Image Analyst
Image Analyst 2022년 7월 4일
OK since my solution of skipping that particular file worked, could you please click the "Accept this answer" link? Thanks in advance. 🙂

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 File Operations에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by