How to rename many files efficiently?
3 views (last 30 days)
Show older comments
I'm running Matlab 7.5.0 (R2007b) in Unix, and I would like to rename all files in a directory by appending something to the filename, e.g. "A" would become "A_1", "B" would become "B_1" etc.
Note that the original files are not mat-files, but this shouldn't make a difference.
Right now I'm doing this using a loop like this:
for i = 1 : length(FileList)
movefile([MyDir FileList{i}] , [MyDir FileList{i} '_1']);
end
However, this is very slow. For 3500 files it takes around 15 minutes, or about 0.25 seconds per file.
Does anyone know a faster way to do this?
P.S. I've also tried executing a unix command from Matlab within the loop, of the sort '!mv ...', but that wasn't faster either.
2 Comments
Matt Kindig
on 9 Jul 2013
Edited: Matt Kindig
on 9 Jul 2013
It's not Matlab, but I have used this freeware program (Renamer: http://www.den4b.com/?x=products&product=renamer) for many years to do this. It is rather flexible (like it can run regexp, for example), and works well for this task. It is also rather fast on a large number of files.
Answers (1)
See Also
Categories
Find more on File Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!