read every audio file in folder and sequentially name them in matlab

You can use the dir function to get a list of all the audio filenames in the folder. Then, you can loop through the list, read each audio file in turn using the audioread function, and sequentially name them.

Here's an example code snippet that does this:

main.m
folder = 'path/to/folder'; % Enter the full path to the folder here
files = dir(fullfile(folder, '*.wav')); % Get a list of all the .wav files in the folder
for i = 1:length(files)
    filename = fullfile(folder, files(i).name); % Get the full filename
    [audio, fs] = audioread(filename); % Read the audio file
    % Sequentially name the audio file
    newfilename = sprintf('%03d.wav', i); % Use a 3-digit prefix, e.g. 001.wav, 002.wav, etc.
    % Write the audio file with the new name
    audiowrite(fullfile(folder, newfilename), audio, fs);
end
554 chars
11 lines

This code will rename all the .wav files in the folder with 3-digit sequential names (e.g. 001.wav, 002.wav, etc.). You can modify the code for other audio file formats as well by changing the *.wav wildcard in the dir function call.

related categories

gistlibby LogSnag