MATLAB: How to check if a directory(folder) exists

directory folder_creation

I am trying to create folders using mkdir, but if I have already created that folder, how do I check that before creating it. a = mkdir(directorylocation,text1) returns 1 in variable a if the directorylocation\text1 is created and if the directory exists. What is the function or condition that checks whether directorylocation\text1 exists

Best Answer

well, I suppose you want to create if it doesn't exist, after checking... so you could do it like that:
if ~exist(yourFolder, 'dir')
mkdir(yourFolder)
end
It basically check if youFolder does not exist. If that's true, it creates youFolder.
Cheers.
Related Question