My code creates files, uses them and then deletes them. The deletion part does not always work
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi,
My code is built in a way that data files and folders are created, used and then deleted.
I've noticed that every now and then the deletion part doesn't work. It's strange becasue if I run the same task many times in a loop it works most of the time but every now and then it doesn't (with the same data). So, I suspect the problem has to do with the way MATLAB is configured on my PC, and maybe something that has to do with permissions (?).
The actual code for deletion is simple:
delete output.txt
rmdir(results_dir, 's')
I also tried using the windows command:
system(['rmdir /s /Q "', folder_to_delete '"'])
but the same problem occurs here too..
I'd be happy to hear some ideas :) Thanks!
Iddo
0 comentarios
Respuestas (2)
Stephen23
el 26 de Sept. de 2017
Editada: Stephen23
el 26 de Sept. de 2017
Sometimes pausing helps, because OS operations do seem to take a finite amount of time:
delete output.txt
pause(1)
rmdir(results_dir, 's')
I created some temporary directories filled with files (for zipping into compressed file) and found that the only reliable way to delete them was to use the time to create and copy all the files as an approximate measure of the folder complexity and call pause(2*toc) before deleting the folder. I guess it gave enough time for my (ancient) windows to catch up with itself.
Jan
el 26 de Sept. de 2017
Editada: Jan
el 26 de Sept. de 2017
You cannot delete folders with limited user privileges, if they have been created with elevanted admin privilegs. A single file created with admin privilegs does not allow to delete the parent folder also. Therefore it is required to check the permissions of the folders and the files. Perhaps the blocking file or folder reveals more details about of the source of the problem.
Then current description "the deletion part doesn't work" is not clear enough. Please provide the error message obtained by:
[status, msg] = rmdir(results_dir, 's');
if status ~= 0
error('RMDIR Failed: %s', msg);
end
0 comentarios
Ver también
Categorías
Más información sobre Entering Commands en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!