score:1

i was able to fix this script. thanks for your help, everyone!

tell application "finder"
-- define the full path to your data
set student_data_folder to folder posix file "/users/jarrett/desktop/scripttest"

-- get the student folders, ignoring hascontent & empty incase they have already been created
set all_student_folders to every folder of student_data_folder whose name is not in {"hascontent", "empty"}

--create the hascontent & empty folders if they don't exist
set hascontent_folder to my checkfolderexists("hascontent", student_data_folder)
set empty_folder to my checkfolderexists("empty", student_data_folder)

-- now loop through all student folders doing the sort based on how many subfolders     they have
repeat with student_folder in all_student_folders
    repeat with info_folder in student_folder
        if (get the (count of files in info_folder) > 0) then
            -- its hascontent
            move student_folder to hascontent_folder
        else
            -- it's empty
            move student_folder to empty_folder
        end if
    end repeat
end repeat

end tell

on checkfolderexists(fname, host_folder)
tell application "finder"
    if not (exists folder fname of host_folder) then
        return make new folder at host_folder with properties {name:fname}
    else
        return folder fname of host_folder
    end if
end tell
end checkfolderexists

score:1

hi i had a quick test of your script. and found if there is more than one item, folder or file in the student info folder they will be counted. therefore the script will break.

if the student info folder has sub folders with files and no files in the student info folder itself then the student info folder will be moved to the empty folder.

i just tried this and it seems to work better.

the idea is to get the kind of items the student info folder contains. then check if anything is something other than a folder..

if it is the no need to check any more. exit the second repeat,do which ever move needed. and the continue with going on to the next folder within the first repeat.

hope this helps.

    tell application "finder"
    -- define the full path to your data
    set student_data_folder to folder posix file "/users/foo/desktop/desktop --misch/students"

    -- get the student folders, ignoring hascontent & empty incase they have already been created
    set all_student_folders to every folder of student_data_folder whose name is not in {"hascontent", "empty"}

    --create the hascontent & empty folders if they don't exist
    set hascontent_folder to my checkfolderexists("hascontent", student_data_folder)
    set empty_folder to my checkfolderexists("empty", student_data_folder)

    -- now loop through all student folders doing the sort based on how many subfolders     they have

    repeat with student_folder in all_student_folders

        #get every item including within sub folders
        set thecontents to kind of entire contents of student_folder

        #set your bool
        set nofiles to false

        #check if there is anything other than folders
        repeat with i from 1 to number of items in thecontents

            set this_item to item i of thecontents

            if this_item is not equal to "folder" then

                #set the bool to reflect there are files
                set nofiles to false

                #found a none folder item so no need to continue
                exit repeat
            else

                set nofiles to true
            end if

        end repeat

        #do your moves
        if nofiles then
            move student_folder to empty_folder
        else
            move student_folder to hascontent_folder
        end if

    end repeat

end tell

on checkfolderexists(fname, host_folder)
    tell application "finder"
        if not (exists folder fname of host_folder) then
            return make new folder at host_folder with properties {name:fname}
        else
            return folder fname of host_folder
        end if
    end tell
end checkfolderexists

Related Query