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
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.
채택된 답변
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
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 Center 및 File Exchange에서 File Operations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!