function Lab4Checker
message = '';
d=dir('*.zip');
zipName = d.name;
d = dir;
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:8
   fileprefixes = {'2','3','7','10','11','13','15','17'};
   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 problem2 format %%%%%%%%%%%%%%
dummy = which('problem2'); % needed to refresh cache
try
    z = problem2(5,5);
catch
    Finish('problem2.m either does not take 2 arguments or does not return 1 argument',tempFolderName);
    return
end
%%%%%%%%%%%%%%% check problem3 format %%%%%%%%%%%%%%
dummy = which('problem3'); % needed to refresh cache
try
    [a,b] = problem3(5);
catch
    Finish('problem3.m either does not take 1 argument or does not return 2 arguments',tempFolderName);
    return
end
%%%%%%%%%%%%%%% check problem7 format %%%%%%%%%%%%%%
dummy = which('problem7'); % needed to refresh cache
try
    z = problem7(5,5,5);
catch
    Finish('problem7.m either does not take 3 arguments or does not return 1 argument',tempFolderName);
    return
end
%%%%%%%%%%%%%%% check problem10 format %%%%%%%%%%%%%%
dummy = which('problem10'); % needed to refresh cache
try
    z = problem10(5,5);
catch
    Finish('problem10.m either does not take 2 arguments or does not return 1 argument',tempFolderName);
    return
end
%%%%%%%%%%%%%%% check problem11 format %%%%%%%%%%%%%%
dummy = which('problem11'); % needed to refresh cache
try
    z = problem11(5,5,5);
catch
    Finish('problem11.m either does not take 3 arguments or does not return 1 argument',tempFolderName);
    return
end
%%%%%%%%%%%%%%% check problem13 format %%%%%%%%%%%%%%
dummy = which('problem13'); % needed to refresh cache
try
    z = problem13([5 5 5 5 5 5]);
catch
    Finish('problem13.m either does not take 1 vector argument or does not return 1 argument',tempFolderName);
    return
end
%%%%%%%%%%%%%%% check problem15 format %%%%%%%%%%%%%%
dummy = which('problem715'); % needed to refresh cache
try
    z = problem15(5);
catch
    Finish('problem15.m either does not take 1 argument or does not return 1 argument',tempFolderName);
    return
end
%%%%%%%%%%%%%%% check problem17 format %%%%%%%%%%%%%%
dummy = which('problem17'); % needed to refresh cache
try
    z = problem17(100);
catch
    Finish('problem17.m either does not take 1 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')
    

