How can I find a sub-folder in the (just in the) current directory ?

11 vues (au cours des 30 derniers jours)
Peter Kerekes
Peter Kerekes le 13 Juil 2017
Commenté : Jigar Gopani le 4 Juil 2022
I'd like to find a sub-folder in the currend directory. If not exist creat it. I tried to use if ~exist(,'file') but this search in other folders too, and find a sub-folder with the same name in other folder, but in the current directory not exist that sub-folder.

Réponse acceptée

C.J. Harris
C.J. Harris le 13 Juil 2017
You can specify exist to only look in the current directory. For example:
lFolder = 'MyFolder';
if(exist([cd filesep lFolder]) == 7)
disp('Folder found!')
end
  2 commentaires
Jan
Jan le 13 Juil 2017
Modifié(e) : Jan le 13 Juil 2017
Prefer fullfile to consider if cd replies e.g. 'c:\'.
if exist(fullfile(cd, lFolder), 'file') == 7
Calling exist(name) without 2nd input is critical: It replies 1 if a variable with this name is existing. Therefore exist should be used with the specifier of what kind of object you are searching in general.
Jigar Gopani
Jigar Gopani le 4 Juil 2022
Why == 7 is used?

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Search Path dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by