【发布时间】:2012-10-01 20:26:24
【问题描述】:
我尝试编写检查文件是否打开的代码。如果是这样,当文件没有关闭时,屏幕上会打印一条警告消息。
我猜我没有正确使用“fclose”,因为通过这种方式,我得到了错误:
??? Error using ==> fclose
Invalid file identifier. Use fopen to generate a valid file identifier.
Error in ==> fileisopen at 4
fclose(fid);
我尝试不使用 fclose 函数,它可以工作,但是当我打开文件时,我收到一条消息,指出该文件仅供阅读。
这是我的代码:
path_of_file = 'C:\Documents and Settings\erezalon\Desktop\data.xls';
[fid msg_file] = fopen(path_of_file, 'a');
fclose(fid);
while (fid == -1)
errormsg = strcat('the file: ', path_of_file, ' is open. please close it!');
waitfor(msgbox(errormsg,'Error'));
[fid msg_file] = fopen(path_of_file, 'a');
fclose(fid);
end
【问题讨论】:
-
您对相关文件 (data.xls) 有写入权限吗?
-
@aganders3,你是什么意思?谢谢。