Error using rmdir
Mostra commenti meno recenti
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 Commento
Jason
il 16 Nov 2011
Risposta accettata
Più risposte (6)
ewnetu bee
il 26 Gen 2015
2 voti
Note: You may need administrator privileges to complete the installation. open ur matlab as run as administrator it works for me simple .
Sergio Santos
il 11 Giu 2015
1 voto
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
il 16 Nov 2011
0 voti
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
il 16 Nov 2011
0 voti
Jason Ross
il 16 Nov 2011
0 voti
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 Commento
Justin Marrott
il 1 Dic 2021
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
il 16 Nov 2011
0 voti
Categorie
Scopri di più su File Operations in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!