MATLAB: Trouble calling files using dir command

calling folderdirfilefolderimage processingMATLABpng

ImageFiles = dir(DBImages);
%%%extracts information of all files whose filename end with `.png?.
^^ This line of code was given to me by my professor and seems to have worked for everyone else, but I can't get it to call the images in my DBImages folder. When I try to run the script, I get this error:
Undefined function or variable 'DBImages'.
I'm not really sure why my DBImages file can't be found; I selected it and clicked on "add folder and subfolders to path," which I figured would make it accessible, but I'm still receiving the asme error. There are no spelling mistake here either. I'm not sure, but I don't think I should need any special toolboxes or anything, as DBImages is just a folder with a few .m files and a lot of .png files. Any thoughts?

Best Answer

I'm not surprised it does not work. The variable DBImages should probably be assigned a string at some point prior to calling dir. Just learn how the function dir works instead:
files = dir('folderpath\*.png')
For example
files = dir('C:\MyImages\*.png')
if DBImages is the folder name, then you probably just failed to make it a string
files = dir('DBImages')
Although the above is possible, I recommend adding the entire folder path, with the only downside being that you have to alter the script if you move the folder.