필터 지우기
필터 지우기

How to get Matlab to unlock or release a directory?

조회 수: 49 (최근 30일)
Scott
Scott 2015년 6월 30일
댓글: Scott 2015년 7월 1일
I have scripts that create a temporary directory to store intermediate files created during processing. At the end of the scripts I want to clean this temporary directory out and remove the directory. I can remove the files that I create, but when I run the rmdir() command, it will usually fail with the message "MATLAB:RMDIR:SomeDirectoriesNotRemoved". If I go into the file system and do a "ls -al" command, I will see that there is a Matlab lock file or something in the directory. It will go away if I shut down Matlab. Unfortunately it's not easy to recreate, because I've tried creating a directory from the command line, adding, modifying and removing a few files, and then removing the directory and it always seems to work fine. Something about running my scripts as a whole is causing Matlab to lock the temporary directory, and I don't know a way to unlock it.
  댓글 수: 3
Walter Roberson
Walter Roberson 2015년 6월 30일
<<If a file delete request is sent to a file on an NFS server while an NFS client still has the file open, NFS will create a file with the ".nfsX" extension, where "X" can be any number of characters. This allows the NFS server to maintain the file until all dependent processes on the file have been terminated.>>
This suggests that there is an open file in the directory. Perhaps something you did not fclose() ?
I think the inode of the .nfs* file should be the same as that of the file that is thought to be open, so if you record the ls -i before the rmdir and then look at the ls -i of the .nfs* file, I suspect you should find a correspondence.
Scott
Scott 2015년 7월 1일
That was it. I found a function call that didn't fclose its file ID, and the inode helped me to quickly figure out which one it was. Thank you!

댓글을 달려면 로그인하십시오.

답변 (2개)

Guillaume
Guillaume 2015년 7월 1일
Are all handles to files in the temp directory closed?
Does
fclose('all')
help?

Walter Roberson
Walter Roberson 2015년 6월 30일
Make sure that you cd out of the directory before removing it.
  댓글 수: 4
Image Analyst
Image Analyst 2015년 6월 30일
"I do cd to the directory" - that's exactly what he said not to do. That probably IS the problem. For one thing, there's no need to cd to any directory - I almost never do. You can use fullfile() and save things to the folder using the full file name without actually having the folder be the current directory. So, if you did cd into it, then cd out of it before you call rmdir().
If that still does not work, you can find out what has a hold on it with the shareware program called "unlocker" (Google it). It will pry off whatever program's grubby hands are on it.
Walter Roberson
Walter Roberson 2015년 6월 30일
편집: Walter Roberson 2015년 6월 30일
Scott cd'd to the containing directory, not the directory itself.
unlocker appears to be an MS Windows program, but "ls -al" is a Unix command so unlocker would not be applicable.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Search Path에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by