stages = dir('Level*');
stages = {stages.name};
D = pwd;
for s =1:length(stages)
    files = dir([stages{s}, filesep, '*sectors.tif']);
    files = {files.name};
    for f = 1:length(files)
        file = files{f};
        file = file(1:end-12);
        if ~exist([D, filesep, stages{s}, filesep, file], 'dir')
            mkdir([D, filesep, stages{s}, filesep, file]);
        end
        tomove = dir([stages{s}, filesep, file, '*']);
        tomove = {tomove.name};
        for m=1:length(tomove)
            if ~isdir([stages{s}, filesep, tomove{m}])
                [STATUS,MESSAGE,MESSAGEID] = movefile([stages{s}, filesep, tomove{m}],[stages{s}, filesep, file, filesep, tomove{m}]);
            end
        end
    end
stages{s}
end