Error using rmdir

91 次查看(过去 30 天)
Jason
Jason 2011-11-16
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.
  1 个评论
Jason
Jason 2011-11-16
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.

请先登录,再进行评论。

采纳的回答

Fangjun Jiang
Fangjun Jiang 2011-11-16
Maybe you need to run rehash() after executing rmdir().
  1 个评论
Walter Roberson
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
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 .

Sergio Santos
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.

Walter Roberson
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.

Jason
Jason 2011-11-16
Well, in my code I call rmdir first, then mkdir immediately after that. mkdir reports an error because the directory does already exist, but it exists because rmdir didn't delete the folder.

Jason Ross
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
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.

请先登录,再进行评论。


Jason
Jason 2011-11-16
Thanks everybody, the rehash suggestion appears to have done the trick.

类别

Help CenterFile Exchange 中查找有关 Environment and Settings 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by