Memo/Matlab

Matlab function : Path Checker

_Ju 2022. 8. 1. 21:44

When you want to check the path using  struct variables,

You can use the following function.

 


#Struct variables

DesktopPath = winqueryreg('HKEY_CURRENT_USER', 'Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders', 'Desktop');
app.handles.path.one = strcat(DesktopPath, '\Test\folder1\');
app.handles.path.two = strcat(DesktopPath, '\Test\folder2\');
app.handles.path.three = strcat(DesktopPath, '\Test\folder3\');

 

#Function

%// how to call function
PathChecker(app.handles.path);



%// Below is the function
function PathChecker (varSet)
	if isa(varSet, 'struct')
    	DataSet = struct2cell(varSet);
        DataSetLength = length(DataSet);
        
        for ii = 1 : DataSetLength
        	Path = DataSet{ii, 1};
            if ~exist(Path, 'dir')
            	mkdir(Path); 
            end
        end
       
        disp('Path Check Completed..');
    end
end

 

#Matlab

#Matlab App Designer