% deleteNonSongs.m

% A Matlab file that renames jpgs of non-songs as wav files 
% and deletes non-song wavs from hard drive
% designed to streamline song sorting using Spectogram & Imatch

% Described in Thompson et al., J. Neurosci., 27:12308-12320, 2007 and
% in more detail in Wu et al., J. Neurosci. Methods, submitted.
%
%Created LC 8-31-07
%UPDATED LC 4-23-08
%UPDATED LC 4-29-08
 
%assures that these variables will be specific 
%to this batch of images & wav files
clear jpgFiles
clear wavFiles
 
%creates a database for each jpg in the folder
toDelete=dir;
 
%lets the function skip the initial two entries
numJPGS=length(toDelete)-2;
 
%creates a list of jpg file names, again, skipping the first two entries
for i=1:numJPGS
    a=i+2;
    b=length(toDelete(a).name)-2;
    if(strmatch(toDelete(a).name(b:end),'jpg'))
        jpgFiles(i,:)=(toDelete(a).name);
    end

end
 
%moves working directory to the folder containing 
%wav files
cd .. 
 
%creates a holding folder for non-song files
mkdir toDelete
 
%moves down the list of jpgs, changes the extension to .wav,
%and moves the files to folder "toDelete" 
for i=1:length(jpgFiles(:,1))
    wavFiles(i,:)=jpgFiles(i,:);
    wavFiles(i,length(jpgFiles(i,:))-2:end)='wav';
    if(exist((wavFiles(i,:)),'file')~=0)
        movefile((wavFiles(i,:)),'toDelete')
    end
end
 
%removes the folder "toDelete"
rmdir ('toDelete','s')


