rmdir frequently fails with the 'MATLAB:RMDIR:SomeDirectoriesNotRe... (2024)

14 Ansichten (letzte 30 Tage)

Ältere Kommentare anzeigen

Kouichi C. Nakamura am 1 Jun. 2016

  • Verknüpfen

    Direkter Link zu dieser Frage

    https://de.mathworks.com/matlabcentral/answers/286871-rmdir-frequently-fails-with-the-matlab-rmdir-somedirectoriesnotremoved-error

  • Verknüpfen

    Direkter Link zu dieser Frage

    https://de.mathworks.com/matlabcentral/answers/286871-rmdir-frequently-fails-with-the-matlab-rmdir-somedirectoriesnotremoved-error

Kommentiert: Volodymyr Zenin am 10 Mär. 2020

Akzeptierte Antwort: Philip Borghesani

In MATLAB Online öffnen

I'm using matlab.unittest.fixtures for unit testing with matlab.unittest.TestCase. The operation involves file conversions, so I think it makes sense to use "setup" method for preparing a work folder and "teardown" for deleting the same folder.

The removal of the folder is done by rmdir function. It works fine, but 3 to 5 times per 10 trials, it fails to delete the folder with an error message 'MATLAB:RMDIR:SomeDirectoriesNotRemoved'.

This is essentially about the same issue, but putting rehash() after rmdir did not help. It's just unpredictable at the moment. I checked the folder's write permission with fileattrib function. Write permission is surely granted, but it still fails.

Only to illustrate the point, I wrote much simpler code. Interestingly, I successfully reproduced the problem.

clc;

str = 'TEMP_FOLDER';

for i = 1:100

if isdir(str)

rmdir(str,'s')

rehash

end

mkdir(str);

A = rand(10);

save(fullfile(str,'A'),'A')

[~,s] = fileattrib(str);

fprintf('UserWrite %d\n',s.UserWrite);

try

rmdir(str,'s');

rehash

catch mex

disp(mex)

throw(mex)

end

fprintf('OK %d\n',i);

end

Although it's quite random, usually it fails within 10 trials.

UserWrite 1

OK 1

UserWrite 1

OK 2

UserWrite 1

MException with properties:

identifier: 'MATLAB:RMDIR:SomeDirectoriesNotRemoved'

message: 'D:\xxxxx\TEMP_FOLDER could not be removed.'

cause: {0x1 cell}

stack: [0x1 struct]

D:\xxxxx\TEMP_FOLDER could not be removed.

Does anyone know how to solve this? I tested on Windows 7 (R2016a); the same code worked on OS X (R2016a).

2 Kommentare

Keine anzeigenKeine ausblenden

Walter Roberson am 1 Jun. 2016

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/286871-rmdir-frequently-fails-with-the-matlab-rmdir-somedirectoriesnotremoved-error#comment_370369

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/286871-rmdir-frequently-fails-with-the-matlab-rmdir-somedirectoriesnotremoved-error#comment_370369

As a data point: on R2016a on OS-X, none of the rmdir fail.

Kouichi C. Nakamura am 2 Jun. 2016

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/286871-rmdir-frequently-fails-with-the-matlab-rmdir-somedirectoriesnotremoved-error#comment_370394

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/286871-rmdir-frequently-fails-with-the-matlab-rmdir-somedirectoriesnotremoved-error#comment_370394

Yes, I tried myself too, and the test code worked fine on R2016a on OS X.

Melden Sie sich an, um zu kommentieren.

Melden Sie sich an, um diese Frage zu beantworten.

Akzeptierte Antwort

Philip Borghesani am 2 Jun. 2016

  • Verknüpfen

    Direkter Link zu dieser Antwort

    https://de.mathworks.com/matlabcentral/answers/286871-rmdir-frequently-fails-with-the-matlab-rmdir-somedirectoriesnotremoved-error#answer_224239

  • Verknüpfen

    Direkter Link zu dieser Antwort

    https://de.mathworks.com/matlabcentral/answers/286871-rmdir-frequently-fails-with-the-matlab-rmdir-somedirectoriesnotremoved-error#answer_224239

In MATLAB Online öffnen

This is often caused by interaction with your virus scanner that happens to still be scanning / looking into files that may already have been deleted in the directory. Short of disabling your virus scanner the only solution is wait a short time and retry the operation. I suggest using the status outputs from rmdir to write a short loop something like this: (untested)

for try=1:4

status=rmdir(str,s);

if status==1

break

end

sleep(.1*try)

end

if status==0

warning('mytest:leakedDir','Warning failed to clean up directory %s", str);

end

4 Kommentare

2 ältere Kommentare anzeigen2 ältere Kommentare ausblenden

Kouichi C. Nakamura am 3 Jun. 2016

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/286871-rmdir-frequently-fails-with-the-matlab-rmdir-somedirectoriesnotremoved-error#comment_370678

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/286871-rmdir-frequently-fails-with-the-matlab-rmdir-somedirectoriesnotremoved-error#comment_370678

In MATLAB Online öffnen

Thanks! I examined the effect of pause duration as below. It's working, but looks like you need at least 1 sec or more. However, I'm not sure if this is caused by Antivirus software. When I checked the above code on Mac, no Antivirus software was running.

clc;

str = 'TEMP_FOLDER';

durations = [0 0.1 0.2 0.4 0.8];

c = zeros(10,5);

disp(datestr(now))

tic

for l = 1:10

for k = 5:-1:1

for i = 1:100

if isdir(str)

pause(2);

if isdir(str)

rmdir(str,'s')

pause(2);

end

end

if exist(str,'file')

delete(str)

end

mkdir(str);

A = rand(10);

save(fullfile(str,'A'),'A')

try

status = rmdir(str,'s');

catch exc

disp(exc.message)

status = -1;

pause(2)

rmdir(str,'s'); % try to delete it anyway after wait

end

switch status

case -1

disp(exc.message);

c(l,k) = c(l,k) + 1;

case 0

warning('mytest:leakedDir','Warning failed to clean up directory %s', str);

c(l,k) = c(l,k) + 1;

case 1

fprintf('OK %d\n',i);

end

pause(durations(k));

end

fprintf('Failed %d times for pause duration %f.\n',c(l,k),durations(k));

end

end

rmdir frequently fails with the 'MATLAB:RMDIR:SomeDirectoriesNotRe... (6)

Philip Borghesani am 3 Jun. 2016

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/286871-rmdir-frequently-fails-with-the-matlab-rmdir-somedirectoriesnotremoved-error#comment_370682

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/286871-rmdir-frequently-fails-with-the-matlab-rmdir-somedirectoriesnotremoved-error#comment_370682

Bearbeitet: Philip Borghesani am 3 Jun. 2016

Your test never fails on my Win7 machine running with Kaspersky AV and MATLAB R2015a or R2016a. This sort of thing is dependent on many software variables.

For any final work around I suggest retrying failed rmdirs instead of a fixed pause duration. It is generally impossible to determine with any certainty how long a pause would need to be and a temporary spike in system use could increase the needed duration. Your code will also run faster without a hard coded pause in each loop.

Kouichi C. Nakamura am 3 Jun. 2016

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/286871-rmdir-frequently-fails-with-the-matlab-rmdir-somedirectoriesnotremoved-error#comment_370692

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/286871-rmdir-frequently-fails-with-the-matlab-rmdir-somedirectoriesnotremoved-error#comment_370692

Bearbeitet: Kouichi C. Nakamura am 3 Jun. 2016

Thanks a lot. Your report made me rethink of the culprit and I think I just found one! It's Dropbox. I put everything in Dropbox and it has been interfering file removal. When I paused Dropbox, I got no errors with the code at the top. But when I resumed Dropbox, I got loads of errors. And that was reproducible. Again Thank you for your input.

Volodymyr Zenin am 10 Mär. 2020

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/286871-rmdir-frequently-fails-with-the-matlab-rmdir-somedirectoriesnotremoved-error#comment_807898

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/286871-rmdir-frequently-fails-with-the-matlab-rmdir-somedirectoriesnotremoved-error#comment_807898

Thank you, Philip Borghesani, for giving this solution - I had the same problem as the Kouichi C. Nakamura, and I suspect OneDrive in interference... By the way, please correct your answer: 1) try cannot be used as variable - it is kind of function in new Matlab; 2) there is no more such function as sleep, one should use pause instead.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Andy Campbell am 2 Jun. 2016

  • Verknüpfen

    Direkter Link zu dieser Antwort

    https://de.mathworks.com/matlabcentral/answers/286871-rmdir-frequently-fails-with-the-matlab-rmdir-somedirectoriesnotremoved-error#answer_224238

  • Verknüpfen

    Direkter Link zu dieser Antwort

    https://de.mathworks.com/matlabcentral/answers/286871-rmdir-frequently-fails-with-the-matlab-rmdir-somedirectoriesnotremoved-error#answer_224238

Have you tried using the TemporaryFolderFixture or the WorkingFolderFixture?

1 Kommentar

-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden

Kouichi C. Nakamura am 2 Jun. 2016

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/286871-rmdir-frequently-fails-with-the-matlab-rmdir-somedirectoriesnotremoved-error#comment_370512

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/286871-rmdir-frequently-fails-with-the-matlab-rmdir-somedirectoriesnotremoved-error#comment_370512

Bearbeitet: Kouichi C. Nakamura am 2 Jun. 2016

Wow, I did not know there are specific types of fixture already available. Good to know, thanks!

Documentation says

Before it deletes the folder, the fixture clears from memory the definitions of any MATLAB-files, P-files, and MEX-files that are defined in the temporary folder.

Yes, this sounds like related to my issue.

Melden Sie sich an, um zu kommentieren.

Melden Sie sich an, um diese Frage zu beantworten.

Siehe auch

Kategorien

MATLABLanguage FundamentalsLoops and Conditional Statements

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Tags

  • matlab
  • rmdir
  • windows

Produkte

  • MATLAB

Community Treasure Hunt

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

Start Hunting!

Es ist ein Fehler aufgetreten

Da Änderungen an der Seite vorgenommen wurden, kann diese Aktion nicht abgeschlossen werden. Laden Sie die Seite neu, um sie im aktualisierten Zustand anzuzeigen.


Translated by rmdir frequently fails with the 'MATLAB:RMDIR:SomeDirectoriesNotRe... (12)

rmdir frequently fails with the 'MATLAB:RMDIR:SomeDirectoriesNotRe... (13)

Website auswählen

Wählen Sie eine Website aus, um übersetzte Inhalte (sofern verfügbar) sowie lokale Veranstaltungen und Angebote anzuzeigen. Auf der Grundlage Ihres Standorts empfehlen wir Ihnen die folgende Auswahl: .

Sie können auch eine Website aus der folgenden Liste auswählen:

Amerika

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europa

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom(English)

Asien-Pazifik

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
  • 日本Japanese (日本語)
  • 한국Korean (한국어)

Kontakt zu Ihrer lokalen Niederlassung

rmdir frequently fails with the  'MATLAB:RMDIR:SomeDirectoriesNotRe... (2024)
Top Articles
Team USA basketball schedule, roster for 2024 Paris Olympics as LeBron James, Stephen Curry, more eye gold
Tracking Team USA's roster for 2024 Olympic Games in Paris
Karl Torp Height
Irela Torres Only Fans
University of Louisville Libraries on LinkedIn: #bannedbooks #censorship #uofl #firstamendment #studentlife #librarylife
Best Zyn Flavors Ranked
Episode 163 – Succession and Legacy • History of the Germans Podcast
Stanford Rival Crossword Clue
Best Seafood Buffet In Laughlin Nevada
Was bedeutet "x doubt"?
Nsu Kpcom Student Handbook
Fatshark Forums
Hamboards Net Worth 2022
Bingo Kans Berekenen
Flappy Bird Cool Math Games
14314 County Road 15 Holiday City Oh
Estrella Satánica Emoji
My Time Banner Health
My Eschedule Greatpeople Me
KMST ver. 1.2.178 – Tallahart & the Long Awaited Balance Patch!
102Km To Mph
Espn Masters Leaderboard
Aunt Nettes Menu
OC IDEAS TO DRAW [80+ IDEAS!] ✍🏼 | Spin the Wheel - Random Picker
Saint Lukes Epulse
Mmastreams.com
Pokerev Telegram
Dutchessravenna N Word
Coverwood Terriers For Sale
Dl Delta Extranet
Unblocked Games 66E
Planet Zoo Obstructed
Walmart Car Service Near Me
Paper Io 2 Unblocked Games Premium
Längen umrechnen • m in mm, km in cm
Jessica Oldwyn Carroll Update
Morning Call Obits Today Legacy
Bernadette Peters Nipple
Patriot Ledger Obits Today
Alylynn
Rydell on LinkedIn: STARTING TODAY you no longer have to wait in a long line to get your oil…
Zuercher Portal Inmates Kershaw County
Damaged car, damaged cars for sale
Gowilkes For Rent
Bbc Numberblocks
Ebony Ts Facials
Rune Factory 5 Dual Blade Recipes
The 7 best games similar to Among Us for Android - Sbenny’s Blog
Toldeo Craigslist
Jili Game Cityjili
Physician Dressed As A Sorceress Crossword Clue
The Emperor's New Groove | Rotten Tomatoes
Latest Posts
Article information

Author: Manual Maggio

Last Updated:

Views: 5951

Rating: 4.9 / 5 (69 voted)

Reviews: 92% of readers found this page helpful

Author information

Name: Manual Maggio

Birthday: 1998-01-20

Address: 359 Kelvin Stream, Lake Eldonview, MT 33517-1242

Phone: +577037762465

Job: Product Hospitality Supervisor

Hobby: Gardening, Web surfing, Video gaming, Amateur radio, Flag Football, Reading, Table tennis

Introduction: My name is Manual Maggio, I am a thankful, tender, adventurous, delightful, fantastic, proud, graceful person who loves writing and wants to share my knowledge and understanding with you.