MATLAB: How to find a sub-folder in the (just in the) current directory


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.

Best Answer

  • You can specify exist to only look in the current directory. For example:
    lFolder = 'MyFolder';
    if(exist([cd filesep lFolder]) == 7)
    disp('Folder found!')