我有一个名为“目录”的文件夹,大约有1000个子文件夹。每个子文件夹(“学生”)包含一个或多个子文件夹,其中包含一个或多个文件。是否可以编写一个脚本:
显然,因此,我需要“Directory”文件夹中的两个文件夹:一个名为“Bad”,其中包含包含一个文件夹的所有文件夹,另一个名为“Good”,其中包含包含多个文件夹的所有文件夹一个文件夹。换句话说,我希望分类法来自:
/Directory/Billy/Grades
/Directory/Billy/Student_Info
/Directory/Bob/Grades
/Directory/Bob/Student_Info
/Directory/Joe/Student_Info
/Directory/George/Grades
要:
/Directory/Good/Billy/Grades
/Directory/Good/Billy/Student_Info
/Directory/Good/Bob/Grades
/Directory/Good/Bob/Student_Info
/Directory/Bad/Joe/Student_Info
/Directory/Bad/George/Grades
答案 0 :(得分:3)
在此之前,它使用了一些您可以在将来使用的核心Finder和AppleScripting创意。
请先备份您的数据,以防万一。
tell application "Finder"
-- Define the full path to your data
set student_data_folder to folder POSIX file "/Users/Foo/Desktop/bar/students/data"
-- Get the student folders, ignoring good & bad incase they have already been created
set all_student_folders to every folder of student_data_folder whose name is not in {"Good", "Bad"}
--Create the good & bad folders if they don't exist
set good_folder to my checkFolderExists("Good", student_data_folder)
set bad_folder to my checkFolderExists("Bad", 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
if (get the (count of folders in student_folder) > 1) then
-- Its good
move student_folder to good_folder
else
-- It's bad
move student_folder to bad_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
HTH