Movefile optimization and operation

조회 수: 6 (최근 30일)
Jason
Jason 2012년 9월 13일
Hey, just a short question. When renaming a file with movefile, does Matlab optimize away the move part of movefile when source and destination are in the same directory? I'm performing an operation on a file using a toolbox which writes in place to the file, but I'd like to prefix the file with a character to denote what operation has occurred. As the file can potentially be quite large, I'd like to avoid actually shuffling the data around.
As an aside, how does movefile actually work? Does it just update the directory table? If so, is there any difference in the overhead when renaming a file, like I am, compared to moving the file to some other directory on the same volume?

채택된 답변

Walter Roberson
Walter Roberson 2012년 9월 13일
The internal behavior is undocumented, and varies with the operating system.
We have evidence that copyfile() on linux invokes the system "cp" command to do the copying. It then becomes plausible that on linux, movefile() would invoke linux's "mv" command. The behaviour would then be determined by the OS utility. In Linux, "mv" on the same filesystem changes directory entries but does not make a copy, and the overhead would be very nearly the same for a rename in the same directory as it would be for moving to a different directory (but rename would only need to write one directory entry rather than two.)
I do not know how movefile() or copyfile() are implemented in MS Windows. It is not clear which OS you are using; the term "volume" is used for both MS Windows and Mac OS-X.
  댓글 수: 1
Jason
Jason 2012년 9월 13일
In my case, it's Linux. Maybe I should have been using the term filesystem. Looks like I shouldn't have any bottlenecks here. Thanks for the quick response.

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

추가 답변 (1개)

Jan
Jan 2012년 9월 13일
편집: Jan 2012년 9월 13일
MOVEFILE has been very slow at least until R2009a, perhaps until today. The C implementation can be much faster: http://www.mathworks.com/matlabcentral/fileexchange/29569-filerename, but it has not been tested under Linux.

카테고리

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