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

10 ビュー (過去 30 日間)
AS
AS 2022 年 6 月 24 日
コメント済み: AS 2022 年 7 月 5 日
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. 🙂
AS
AS 2022 年 7 月 5 日
All done! Thanks again!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFile Operations についてさらに検索

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by