Help with error message: 'MATLAB:MO​VEFILE:Fil​eDoesNotEx​ist' using matlab MOVEFILE command in for loop.

Hello,
I have a simple for loop for sorting multiple files in to a suitable files however I find the code is running but not finding any files.
I have checked fullFileName and the full path is correct and works.
I typically create a 35x1 cell array which has the file names in string prior to running this script.
Have I just made a mistake in the structure of movefile?
Thanks in advance!
sd = uigetdir;
dest = uigetdir;
Q = numel (files);
for k = 1:Q
baseFileName = a(k);
fullFileName = fullfile(sd,baseFileName,'.csv')
movefile('fullFileName','dest')
end
CMD output from movefile:
SUCCESS =
logical
0
MESSAGE =
'No matching files were found.'
MESSAGEID =
'MATLAB:MOVEFILE:FileDoesNotExist'

Answers (1)

fullFileName = fullfile(sd, [baseFileName,'.csv'])

8 Comments

I get a similar issue. Only now my fullFileName contains a 1x2 Cell with the following in:
fullFileName =
1×2 cell array
{'C:\Users\user\Documents\Data Sets\folder1\filename'} {'C:\Users\user\Documents\Data Sets\Folder2\.csv'}
Error text
Error using movefile
No matching files were found.
Error in Untitled2 (line 8)
movefile('fullFileName','dest')
Both fullfile commands below give the same result.
fullFileName = fullfile(sd, baseFileName + ".csv")
fullFileName = fullfile(sd,baseFileName,'.csv')
The script gives the same failure message as in the op.
what is the output of the first of those two ? What are class(sd) and class(baseFileName) ?
The second cannot possibly work . It would try to use .csv as the file name .
I apologise there was a difference.
The original has
C:\....\filename\.csv
Your corrected version :
C:\....\filename.csv
The error is now:
Error using movefile
No matching files were found.
Error in Untitled2 (line 8)
movefile('fullFileName','dest')
sd is the directory of the files I want to move
baseFileName is just the name of the file called from a a X,1 cell of strings.
uigetdir() returns a fully qualified directory name, and you are using fullfile() to attach that fully qualified directory name to a file name. Therefore your variable fullFileName will contain a character vector that names a file including directory information.
If you had instead passed a name that did not have directory information, then the search would be relative to the current directory first, after which it would go along the MATLAB search path looking to see if it could find a match for the name (if it did not exist in the current directory.)

Sign in to comment.

Categories

Find more on Environment and Settings in Help Center and File Exchange

Asked:

on 10 Dec 2018

Commented:

on 11 Dec 2018

Community Treasure Hunt

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

Start Hunting!