MATLAB: Read Files from Directory

directoriesmultiple files

Hey,
I'd like to be able to give a program a directory, and then have it run a second program on all files in that directory. For example, say I have a function, myFun(filePath) that reads, processes, and displays data from the file specified by filePath. Now, I'd like to write another function, in pseudocode below:
funtion dirFun(dirPath)
f = files(dirPath);
for x = 1:length(files);
myFun(f[x]);
end
Something like this. I want a function, here "files" which will return all of the file names within the directory, so that I can run the program on all my files. Is there such a function in MATLAB?

Best Answer

The function is dir().
Files=dir('*.*');
for k=1:length(Files)
FileNames=Files(k).name
end