MATLAB: Load a file with ‘dir’

dir

Hello,
I want to load a file containing multiple data disorganized and I do not know why I get an error message on the load function. Someone would have an idea?
thank you
clc
clear all
close all
%--exercice2----------------------
contenu = dir('C:\Users\williot\Dropbox\UQTR 2013 - 2015\Matlab\MatLab EPK6064\Fichiers_Travail2');
for file = 1:length(contenu)
if strcmp(contenu(file).name,'.')==0 && strcmp(contenu(file).name,'..')==0
file_name = contenu(file).name;
load(file_name)
end
end
??? Error using ==> load Unable to read file Chronique_DataFRP_sujet04.mat: No such file or directory.
Error in ==> exercice2__a_williot at 12 load(file_name)

Best Answer

You are getting the results of dir from a different directory than the current directory. I.e., you explicitly put the path in the string argument to dir. So the file_name in question exists in that directory, but not in the current directory. You either need to use the full path name for the file to load it, or cd to that directory. E.g.,
load(['C:\Users\williot\Dropbox\UQTR 2013 - 2015\Matlab\MatLab EPK6064\Fichiers_Travail2\' file_name])