How do I rename sound files in a folder?
3 views (last 30 days)
Show older comments
I have 100 sounds in a folder under bad names and I want rename each sound to "stim1", "stim2", ect... How do rename these sounds in matlab?
0 Comments
Answers (1)
OCDER
on 3 Aug 2018
Use movefile to rename a file from BAD_NAME --> GOOD_NAME. But, BACKUP YOUR FILES before doing this for the first time! Bugs can be costly x.x
Use dir, fullfile, and maybe regexprep to find and replace filename string, before using movefile. Here's an example to get you started.
A = dir('**/*.wav');
for j = 1:length(A)
% If your bad file name has a sequence ID #, like Bad_121_blah.wav, extract "121" first via regexp.
% Ex: Bad_121 -> stim121.wav, figure out how to extract "121" via regexp(BadName, '\d+', 'match')
BadNameNum = regexp(A(j).name, '\d+', 'match');
GoodName = sprintf('stim%s.wav', BadNameNum{1});
movefile(fullfile(A(j).folder, A(j).name)), fullfile(A(j).folder, GoodName));
end
0 Comments
See Also
Categories
Find more on Audio and Video Data 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!