File Exchange Pick of the Week

Our best user submissions

MATLAB for File Management 5

Posted by Jiro Doke,

Jiro's pick this week is a set of functions for operating on files and folders by Frederic Moisy.

I use MATLAB for analyzing data and creating tools for data analysis. But I like MATLAB so much that I use it for things other than regular work stuff. That's why when I came across Frederic's entry, it made me smile. This would certainly help me manage my files on my computer. With his collection of files, you can easily navigate to folders, manage folders, and view/manipulate file names.

To get the file names of my image files in "image1" and "image2",


To rename my image files by replacing certain text patterns,

cd image1
renamefile('*.jpg', 'im', 'newIm');
cd ../image2
renamefile('*.jpg', 'im', 'oldIm');
cd ..

One suggestion I have is for "renamefile" to work with multiple folders at once. But it's pretty useful as it is!


Let us know what you think here.

Get the MATLAB code

Published with MATLAB® 7.10


Comments are closed.

5 CommentsOldest to Newest

KE replied on : 1 of 5

Very helpful. Would be nice if Matlab itself integrated more file / folder management tools (perl?)

Clayton Chu replied on : 2 of 5

Couldn’t you just use the ! command to perform a command in a system shell and get the exact same result?

jiro replied on : 3 of 5


Perhaps! I guess I don’t know all the DOS/System commands to do file manipulation.

Bob replied on : 4 of 5

I don’t think DOS allows wildcard usage as shown in Jiro’s example, and the OS commands for file mangement differ between PC and Unix. This submission does add convenience.

I find MATLAB’s file operations so platform agnostic that I have been known to do shell scripting in MATLAB to get cross platform compatibility.

MATLAB does support Perl BTW.

help perl
Michel R. Bouchard replied on : 5 of 5


I found a bug when the files have no extention and no extention is provided. This happens at line 87. I replaced the original code:
D(ii).name = [prepath,D(ii).name];

D(ii).name = fullfile(prepath,postpath,D(ii).name);

Otherwise great code and very fast!