View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from

5.0 | 1 rating Rate this file 14 Downloads (last 30 days) File Size: 1.89 KB File ID: #40877 Version: 1.3




19 Mar 2013 (Updated )

Reads filename contents of a folder.

| Watch this File

File Information

Reads a group of (fileNames) from a folder specified by (inFolder), and generates the output in the form of a char array.
fileNames is the criteria that specifies the files, e.g., *.jpg. If fileNames is left as a blank (default) this function reads all contents, but this is not preferred since some folders containing images will also have system files such as (Thumbs.db) or (folder.ini) beside subfolders.

Required Products MATLAB
MATLAB release MATLAB 7.8 (R2009a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (3)
17 Oct 2014 Belal

Belal (view profile)


22 Mar 2013 Ahmed A. Selman

Thanks a lot Jan, these are useful comments. However, there is a line of code at the very end:


which removes the newly added directory from the path, just in case it confuses the original (user pre-set) Matlab path.

Once again, this simple function reads the (contents of a folder)-if not specified, these contents could be files and sub-folders.

My regards.

Comment only
21 Mar 2013 Jan Simon

Jan Simon (view profile)

Adding a folder temporarily to the Matlab PATH can have dangerous side-effects. As far as I can see, this is not needed at all, because you use the absolute path name already: "fileNames = fullfile(inFolder)". Here "fullfile" is actually useless, such that I'm confused.
Your code does not distinguish folders and files, but the name of the function and the output implies, that only files are returned.

CHAR matrices are not very useful in Matlab, such that I think this would be better:
function out = folderFiles(varargin)
d = dir(fullfile(vargargin{:}));
out = {d([d.isdir]==0).name};

I like the documentation of this function: (almost) a H1-Line (delete the leading empty comment line), description of inputs and outputs, examples, date and author, "See also" line. This is very good!

Comment only
25 Mar 2013 1.3

1)Unnecessary bits of code are removed.
2)Two new error-check lines are added to detect input arguments' type.
3)File description is slightly modified.

Contact us