Why is the command dir inconsistent about recognizing directories?

Hi All,
I have an application that stores setup data in a specific folder. When it starts it looks to see if that folder exists so it can load the current data. If not it creates the folder and saves default settings. My script was working just fine last week, and today for some reason, it doesn't recognize the folder that it creates as a directory. Specifically if I call d=dir;, and i is the instance of the folder (that I can see in Windows Explorer), then d(i).name is the name of the folder, but d(i).isdir returns a 0. Here's some of the code:
d = dir;
create_data_folder = 1;
for i=1:length(d)
fprintf('The name is %s and isdir is %d\n',d(i).name,d(i).isdir)
if d(i).isdir
if strcmp(d(i).name, 'Folder Name')
create_data_folder = 0;
fprintf('Starting up.\n');
end
end
end
After this, if create_data_folder is 1, it uses a mkdir command to create the folder "Folder Name". Once it's there, sometimes it recognizes it as a directory and sometimes it doesn't! I'd appreciate it if anyone has any ideas. Thanks.
Glenn

댓글 수: 1

Did you try to see what EXIST returns using the 'kind' argument 'dir' and 'file'?

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

 채택된 답변

Image Analyst
Image Analyst 2013년 4월 9일
Here's an alternate way using genpath:
startingFolder = pwd; % or wherever...
folderList = genpath(startingFolder)
baseFolderToSearchFor = '\tests3'
folderToCreate = fullfile(startingFolder, baseFolderToSearchFor)
if strfind(lower(folderList), lower(baseFolderToSearchFor)) > 1
fprintf('Found the %s folder\n', folderToCreate);
else
fprintf('Did not find the %s folder.\nWill create it.\n', folderToCreate);
% mkdir(folderToCreate);
end

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 File Operations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by