Error using rmdir when trying to remove folder

94 ビュー (過去 30 日間)
Felix
Felix 2014 年 10 月 27 日
回答済み: db1024 2022 年 1 月 12 日
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

採用された回答

per isakson
per isakson 2014 年 10 月 27 日
If on Windows, an idea: cmd_rmdir
  1 件のコメント
Felix
Felix 2014 年 10 月 27 日
Thank you per.
with the command it works.
Regards
Felix

サインインしてコメントする。

その他の回答 (3 件)

Roy Talman
Roy Talman 2017 年 7 月 24 日
編集済み: Walter Roberson 2017 年 7 月 24 日
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 2017 年 7 月 24 日
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

db1024
db1024 2022 年 1 月 12 日
I am using MATLAB R2021b Update 2.
I am facing the same issue in the file matlab.io.datastore.mixin.RemoteToLocalFile
function deleteIfLocalCopy(obj)
%DELETEIFLOCALCOPY This helper deletes the temporary local file
% if a local copy was created during construction.
if ~obj.LocalCopyCreated
return;
end
localTempDir = fileparts(obj.LocalFileName);
if exist(localTempDir, 'dir')
rmdir(localTempDir, 's');
end
obj.LocalCopyCreated = false;
end
in my local machine:
Operating System: Microsoft Windows 10 Enterprise Version 10.0 (Build 19042)
Java Version: Java 1.8.0_202-b08 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode
Since RemoteToLocalFile is a built-in MATLAB function, I cannot use the propost solution.

カテゴリ

Help Center および File ExchangeFile Operations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by