필터 지우기
필터 지우기

Error using rmdir

조회 수: 91 (최근 30일)
Jason
Jason 2011년 11월 16일
댓글: Justin Marrott 2021년 12월 1일
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