The problem appears to be a permissions issue when I create the folder, but I am the administrator on my machine and there is no documentation for setting/changing folder permissions in Matlab that I can find.
Error using rmdir
74 ビュー (過去 30 日間)
古いコメントを表示
Guys -
I'm writing a GUI in which I create a directory with the following code:
SessionName = get(handles.SessionName,'String');
%later on...
mkdir(SessionName);
Later on, the user has an option to remove that folder and all its contents by using rmdir:
rmdir(SessionName,'s');
But, every time I call rmdir in my GUI I get the following error:
??? Error using ==> mkdir
Access is denied.
Error in ==> ClusterGUI2>createsession_Callback at 95
mkdir(SessionName);
Error in ==> gui_mainfcn at 96
feval(varargin{:});
Error in ==> ClusterGUI2 at 42
gui_mainfcn(gui_State, varargin{:});
Error in ==> @(hObject,eventdata)ClusterGUI2('createsession_Callback',hObject,eventdata,guidata(hObject))
??? Error while evaluating uicontrol Callback
It's as if MATLAB (R2011a) doesn't recognize the presence of the folder I just created. When I call 'dir', the folder is listed in the directory, but at the command line when I try
rmdir(SessionName,'s');
??? Error using ==> rmdir
No directories were removed.
Any thoughts? This is driving me nucking futs.
採用された回答
Fangjun Jiang
2011 年 11 月 16 日
Maybe you need to run rehash() after executing rmdir().
1 件のコメント
Walter Roberson
2011 年 11 月 16 日
rehash() should only have an effect if you were executing files in that directory. If that is the case, that you were executing files there, then MATLAB might have internal file pointers due to the JIT process, and the solution would be to "clear" the name of each function that was called upon from the directory.
その他の回答 (6 件)
ewnetu bee
2015 年 1 月 26 日
Note: You may need administrator privileges to complete the installation. open ur matlab as run as administrator it works for me simple .
0 件のコメント
Sergio Santos
2015 年 6 月 11 日
Also, I know it might sound silly but check that inside the directory there is no file that is currently open with another program. I had this problem once and I just had just opened a text with notepad. When I closed the file my problems disappeared also.
0 件のコメント
Walter Roberson
2011 年 11 月 16 日
According to the traceback message, you are calling mkdir instead of rmdir. In which case creating the directory again is being denied because the directory already exists.
0 件のコメント
Jason Ross
2011 年 11 月 16 日
I've seen issues where operations will return as "complete" from the OS, but there are still some things that are going on or caches that need to finish flushing. As a diagnostic, try pausing for a few seconds before executing the mkdir. Or put a breakpoint in the debugger and see how long the rmdir takes to delete.
Also, are all the processes using the directory terminated before you end it? Most OS's will not remove a directory if it's still in use by a process. If you change into the directory, make sure you change out of it before you delete it.
1 件のコメント
Justin Marrott
2021 年 12 月 1 日
Really good point tucked into your answer. If your current directory (cd) is in the folder, then it wont delete.
I have been trying to figure what was the problem with some parallel workers not clearing their working folder with rmdir. Your answer finally gave me the answer, I needed to move their working folder out of the folder to be deleted.
参考
カテゴリ
Help Center および File Exchange で Environment and Settings についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!