Matlab movefile() deleted my files
7 views (last 30 days)
Show older comments
Hello everyone,
I have used movefile() to move measurements that have already been evaluated to a subfolder. My source code for this was:
movefile(file, '../Evaluated')
My problem now is that the subfolder is empty and I can no longer find the files on my PC.
Can anyone tell me what has happened and how I can restore the files?
Best regards
Leon
12 Comments
dpb
on 23 Dec 2024
Edited: dpb
on 23 Dec 2024
That's a good catch, @Image Analyst; while it is local to the function and will go away when it exits, inside the function it will indeed alias the builtin path() function. Whether the builtin movefile uses a reference that will resolve to the equivalent of referencing the local path variable instead of the cached path would take more debugging than have inclination to try to do, but it certainly is not a good idea to have done and has at least a reasonable chance of being involved in the problem if not the root cause.
"Use "folder" instead of "path".
Just as an aside coding practice others may not care for, for such local temporary variables such as here, I opt for short...I'd have written that line as
[f,p] = uigetfile('*.mat');
As temporary locally-used throwaways, there's no need for verbose names; just a mnomenic to keep the two straight is sufficient. My $0.02, imo, ymmv, etc., etc., ... of course.
Walter Roberson
on 24 Dec 2024
[file path] = uigetfile('*.mat');
would only affect the path() function if path() was being used in the body of code directly inside the same script/function or inside a script called from that code. In particular, it would not affect the resolution of path() inside a function called by that code. Changing the path variable is not going to affect the movefile() function.
Answers (0)
See Also
Categories
Find more on File Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!