function Lab5Checker
d=dir('*.zip');
zipName = d.name;
tempFolderName = '~ee120';

[success,msg]=mkdir(tempFolderName);
if success ~= 1
    Finish('Cannot make directory',tempFolderName);
    return;
end
warning('off') % will trigger if there is a subdirectory inside the tempFolderName
if ~isempty(msg) % there was already a subfolder present!  Must have old data; get rid of it before unzipping new data
    cd(tempFolderName);
    pause(0.1) % flush buffer
    delete('*.*');
    d = dir;
    pause(0.1) % flush buffer
    if length(d) > 2 % subfolders in there
        rmdir('*','s');
    end
    cd('..');
end
% now you are in the parent directory, and there is an empty temp folder created waiting for the unzipped files
unzip(zipName,'./~ee120')
pause(0.1)
cd('~ee120')

%%%%%%%%%%%%%%% Check to see there are (incorrectly) other folders present %%%%%%%%%%%%%%
d = dir;
for i=3:length(d)
    if d(i).isdir
        Finish(sprintf('The zip file contains a folder named %s, however the zip file should only contain .m files',d(i).name),tempFolderName);
        return;
    end
end

%%%%%%%%%%%%%%% check for problem1...8 existance %%%%%%%%%%%%%%
for i=1:6
    fileprefixes = {'01','02','05','06','29','30'};
    if ~exist(sprintf('problem%s.m',fileprefixes{i}),'file')
       Finish(sprintf('problem%s.m is missing from zip file',fileprefixes{i}),tempFolderName);
       return
   end
end
warning('on')


%%%%%%%%%%%%%%% check problem1 format %%%%%%%%%%%%%%
dummy = which('problem01'); % needed to refresh cache
try
    z = problem01(4);
catch
    Finish('problem01.m either does not take 1 argument or does not return 1 argument',tempFolderName);
    return
end
%%%%%%%%%%%%%%% check problem2 format %%%%%%%%%%%%%%
dummy = which('problem02'); % needed to refresh cache
try
    a = problem02(2);
catch
    Finish('problem02.m either does not take 1 argument or does not return 2 arguments',tempFolderName);
    return
end
%%%%%%%%%%%%%%% check problem5 format %%%%%%%%%%%%%%
dummy = which('problem05'); % needed to refresh cache
try
    problem05();
catch
    Finish('problem05.m either does not take 0 arguments or does not return 0 arguments',tempFolderName);
    return
end
%%%%%%%%%%%%%%% check problem6 format %%%%%%%%%%%%%%
dummy = which('problem06'); % needed to refresh cache
try
    [a,b,c]=problem06(4);
catch
    Finish('problem06.m either does not take 1 argument or does not return 3 arguments',tempFolderName);
    return
end
%%%%%%%%%%%%%%% check problem29 format %%%%%%%%%%%%%%
dummy = which('problem29'); % needed to refresh cache
try
    z = problem29(5);
catch
    Finish('problem29.m either does not take 1 argument or does not return 1 argument',tempFolderName);
    return
end
%%%%%%%%%%%%%%% check problem30 format %%%%%%%%%%%%%%
dummy = which('problem30'); % needed to refresh cache
try
    z=problem30('10','101');
catch
    Finish('problem30.m either does not take 1 vector argument or does not return 1 argument',tempFolderName);
    return
end

%%%%%%%%%%%%%%% No errors! %%%%%%%%%%%%%%
Finish('Scanning complete; any errors found are noted above. (There may be output above that your code produced, unrelated to errors found).', tempFolderName)
warning('on')


function Finish(message, tempFolderName)
warning('off')
disp(message)
d=pwd;
t=find(d=='\');
curdir = d(t(end)+1:end);
if ~isequal(tempFolderName,curdir) % not in the temporary folder; must be in the parent directory
    if exist(tempFolderName,'dir') % in parent directory and the temp folder exists
        cd(tempFolderName)
    end
end
if isequal(tempFolderName,curdir) % now you're in the temp folder
    pause(0.1); % needed to flush the write buffer
    delete('*.*'); % will generate a warning message if there are subdirectories
    pause(0.1); % wait for above to take effect
    d = dir;
    if length(d) > 2 % there are subdirectories
        pause(0.1); % time to flush the buffer
        rmdir('*','s');
    end
    cd('..')
end
d = dir('~ee120');
if ~isempty(d)
    pause(0.1);
    rmdir(tempFolderName,'s');
end
warning('on')
    

