MATLAB Answers

Error using rmdir when trying to remove folder

182 views (last 30 days)
Felix
Felix on 27 Oct 2014
Answered: Felix on 24 Jul 2017
Hi,
I want to remove folders with data in it, unfortunately it doesn't work and I do not really find help in google. On some machines the deletion works, sometimes at least.
I'm using this code:
if( exist(filePath, 'dir') )
rmdir( filePath, 's' );
end
The variable filePath is of class char containing the text:
'C:\Temp\HBTFiles\Current\Output\CS_P1_REGTEST'
I'm receiving the message
Error using rmdir
No directories were removed.
which occurs on the line
rmdir( filePath, 's' );
I'm using Matlab R2012a and Windows7 and I have write permissions on the specified folder. The folder was created in Matlab also, without throwing errors. I wonder how it first recognizes that the folder exists, and when it wants to delete it, it is not able to do so.
Has somebody an idea?
Thanks
Felix

Accepted Answer

per isakson
per isakson on 27 Oct 2014
If on Windows, an idea: cmd_rmdir
  1 Comment
Felix
Felix on 27 Oct 2014
Thank you per.
with the command it works.
Regards
Felix

Sign in to comment.

More Answers (2)

Roy Talman
Roy Talman on 24 Jul 2017
Edited: Walter Roberson on 24 Jul 2017
Try to empty the folder first, you cal do it by:
A = dir( <Dir> )
for k = 1:length(A)
delete([ <Dir> '\' A(k).name])
end
rmdir( <Dir> )

Felix
Felix on 24 Jul 2017
Thanks Roy for your answer.
Unfortunatelly I do no longer have access to matlab, so I can't test that. But any other person finding this post, this might help :)
Regards, Felix

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by