file handle release

8 Ansichten (letzte 30 Tage)
Jane
Jane am 19 Apr. 2011
Hello, I have a problem on the file generated by the matlab. What I do is to open data files one by one and save the meaningful data to this result file. After reading each data file, I closed the data file. At the end of the program, I fclose this result file. And I'm 100% sure the file handle is released in MATLAB. But I found I couldn't remove this result file in windows(when the criteria was set wrong ). It always says "Cannot delet xxx.txt: It is being used by another person or program. Close any programs that might be using the file and try again". I have to close the MATLAB to remove this file. Is there any other way to remove it ? Thank. BTW, I use Windows XP professional.

Antworten (4)

Kaustubha Govind
Kaustubha Govind am 19 Apr. 2011
You could try:
fIDs = fopen('all');
for i = numel(fIDs)
fName = fopen(fIDs(i));
disp(fName);
end
To see if the file handle is somehow still open, and close the ones corresponding to your file.

Jane
Jane am 19 Apr. 2011
Hello Kaustubha, I don't think I'm still keeping the handle. I tried to "clear all" before. I also tried your suggestion. The FID is empty. It sounds like Matlab still keep it somehow.

Jason Ross
Jason Ross am 19 Apr. 2011
Do you have any command windows or other processes open (text editor, etc) to the directory? I've lost count of the number of times I've minimized a command window that is set to a certain directory, then tried to delete that directory and windows generated a similar error.
You can also use the PS Tools to see what processes have file handles open. You can do it through Process Explorer or use the Handle command line version.

Jane
Jane am 19 Apr. 2011
Hi, Jason,
Thanks for your answer and the debug website. I agree with you. This should be an OS issue not a Matlab issue. I still don't think other program set to this directory. But this noon, after getting virtual memory low warning, I closed a few programs and restart the Matlab. This time, with the same program, same operation, I can rename the result file and delete it. I'll use the PS Tool to see what's going on.
Thanks, Jaen

Kategorien

Mehr zu File Operations finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by