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 comentario

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

Iniciar sesión para comentar.

 Respuesta aceptada

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

Más respuestas (0)

Categorías

Más información sobre File Operations en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 9 de Abr. de 2013

Community Treasure Hunt

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

Start Hunting!

Translated by