how can I appropriately get a for loop to extract wav files to sub folders(directories)??

2 views (last 30 days)
My currrent issue is trying to take a folder with 40 .wav files, (10s clips for each instrument that add up to 40s total)
but all are labeled, "01_composer_basson", "01_composer_violin"......"02_composer_basson"....and so on
I cannot seem to write a for loop properly to get all the 10s clips for each .wav into each of their own directories.
I can then break them up and anaylize them by cattinizing them.
How can i fix my loop so i can get each instrument .wav file to the directory?
i have this so far, i apologize in advanced for my lack of matlab skills!
%extracts the audio files from the main folder and puts them into folders
%based on their name.....
function [] = AudioExtract()
File = ls('\\users\audio_stems\');
%folders for seperate instruments
mkdir Basson
mkdir Saxphone
mkdir Clarinet
mkdir Violin
% the original folder all the files are in has 40 .wav files
%10 for each instrumnet
for i=1:42
% first reaults are a . then a ..(
if(File(i,3) ~= '_')
continue
else
if mod(i,3)==0
disp('.');
end
if (strfind(File(1,:), 'basson') ~= 0)
Intsrument = 'Basson';
else
(strfind(File(1,:), 'clarinet') ~=0);
Intrsrument = 'Carinet';
if (strfind(File(1,:), 'saxaphone') ~= 0)
Instrument='Saxaphone';

Accepted Answer

Jan
Jan on 30 Nov 2020
List = dir('\\users\audio_stems\*.wav');
%folders for seperate instruments
mkdir Basson
mkdir Saxphone
mkdir Clarinet
mkdir Violin
for k = 1:numel(List)
Name = List(k).name;
if contains(Name, 'bassson')
Intsrument = 'Basson';
elseif contains(Name, 'clarinet')
Intsrument = 'Basson';
... etc
end
movefile(Name, fullfile(Instrument, Name));
end
  6 Comments
Turbulence Analysis
Turbulence Analysis on 1 Dec 2020
Thanks, Jan.
I have opned a new thread.. Below is the link..
https://www.mathworks.com/matlabcentral/answers/670713-read-files-from-folder-and-subfolder
morgan mcvay
morgan mcvay on 1 Dec 2020
Nevermind, I had my path incorrect for were the dir was searching.......rookie mistake, it returned a 40x1 struct!
Thanks again

Sign in to comment.

More Answers (0)

Categories

Find more on File Operations in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!