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
Source: stackoverflow.com
Related Query
- Moving and Consolidating Folders and Files With AppleScript (Part 2, Need Help Ammending)
- Moving and Consolidating Folders in AppleScript
- List files and folders recursively with numbering
- Forcing files and folders to be dealt with in alphabetical order
- Need help defining ranges and strings with this Looping Split script
- Count files in folder and subfolders, exlucing folders with string
- Need Help Using INDEX and MATCH with a Dynamic Named Range
- Need help using vba to select rows with dynamic data from dynamic sheets and consolidate in a new sheet in excel
- Looping a loop with slight change - opening folders and files, and then do the same loop again but open files from next folder
- VBA script to create folders and move files with certain criteria to those folders
- Some equal values in column A from a CSV file and need to copy values from other files that matches with that column in excel
- Loop over PDF files and transform them into doc with word
- How to find and replace part of a cell with formatted text
- VBA End-user upgrading Microsoft Office 2007 to 2010 (VBA 6 to VBA7) problems and need for documentation, help, tips. (Enough with keywords)
- Is it possible to list all the files and folders in a custom directory - excel vba
- List files in folder and subfolder with path to .txt file
- Excel VBA Count number of rows in all files in folders and subfolders
- VBA - Recursively search through folders and count values within the files found
- Need help summing unit weights and a multi-level parts list
- Need help in vba-excel and Sql query
- Code to read and then write a file into a SQL Server BLOB column producing files with different bytes
- Moving sheets with VBA codes and buttons to a new Workbook
- How to split a mail merge and save files with a merge field as the name
- I need to take 2 columns in an excel sheet and convert them to a data range with column 1 as the headers
- Need help to input If and Vlookup formula into cell using VBA
- Creating folders and new *.xlsx file with macro from template like xlsm file
- Browsing https SharePoint files and folders through local VBA
- expand macro to select all "txt" files in folder A and save as with the same name in other folder B after processing handling
- I need to create a custom (mail merge) email in conjunction with MS Access's and MS Outlooks Data Collection feature
- vba - looping and renaming files and folders
More Query from same tag
- VBA doesn't update Excel links
- Insert function in a cell if another cell changes value
- How to display stimestamps with microseconds in excel corrctly?
- Excel Vba: Sub or Function not defined
- VBA CubeField filter
- Sumifs with date criteria
- Find and Highlight Macro with Confirmation
- Userform: Keep Running Total in Textbox
- Type Mismatch VBA array
- Run-time error '424': Object required for VBA copy/paste macro with unprotect workbook
- Use Excel AdvancedFilter xlFilterCopy to append data
- Path error 5152 when saving Word document using Excel VBA
- How to loop through Two arrays in TWO FOR Each loop
- vlookup vba code autofill not working
- Run-time error '1004' Method 'Rows' of object '_Global' Failed
- Regex to insert new line character after semicolon and remove names before email
- Late binding an array
- Compute subform total
- How to move a shape without selecting it?
- How to identify an fso folder object as a shortcut
- Query SQL Server from Excel with parameters
- Trouble replacing Chr(160) with VBA in excel
- change textarea aws polly in vba to read new text fails
- excel vba countifs formula referencing a changing worksheet name
- Using a variable of Type Range in VLookup in VBA
- Excel VBA using loop
- Code to Generate Sequential Code with a Prefix
- Formula does not work in VBA
- Create Excel spreadsheet using the criteria from another table in MS Access VBA
- Excel interop macro out/ref parameters