Error using rmdir when trying to remove folder

17 views (last 30 days)
Hi
I am trying to remove a folder and all its contents during each run of the for loop. This is the code:
cd 'C:\Temp\A2matlab'
rmdir PsDTestHM1 s
This works well for a few runs and then stops and gives me the following error:
Error using rmdir
C:\Temp\A2matlab\PsDTestHM1\PsDTestHM1.log could not be removed.
C:\Temp\A2matlab\PsDTestHM1 could not be removed.
Error in AbaqusPS (line 1356)
rmdir PsDTestHM1 s
Any suggestions as to what I could be doing wrong?
Thank you.

Answers (1)

Walter Roberson
Walter Roberson on 24 Apr 2017
The files are probably in use. For example you might need to fclose('all') if you wrote to them from within MATLAB. If the log file is a diary then you need to turn diary off (or change diary destinations.) If some external program is writing to the files, you need to make sure the external program has finished.

Categories

Find more on File Operations in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!