diff --git a/matlab/CheckPath.m b/matlab/CheckPath.m
index c20c245c3f6e301492dc5370815b5b4d1e3db13f..0e8e52838911009f4aaeb8c0b019aa6394461a02 100644
--- a/matlab/CheckPath.m
+++ b/matlab/CheckPath.m
@@ -32,9 +32,15 @@ global M_
 DirectoryName = [ M_.dname '/' type ];
 
 if ~isdir(M_.dname)
-  mkdir('.', M_.dname);
+    if exist(M_.dname, 'file')
+        error(['Can''t create subdirectory. You should erase the following file: ' M_.dname])
+    end
+    mkdir('.', M_.dname);
 end
 
 if ~isdir(DirectoryName)
+    if exist(DirectoryName, 'file')
+        error(['Can''t create subdirectory. You should erase the following file: ' DirectoryName])
+    end
     mkdir('.',DirectoryName);
-end
\ No newline at end of file
+end