2

ユーザー adamh の次のスクリプトを使用してフォルダーを統合しました

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

今、私はもう少し助けが必要です。私の分類法は次のようになります。

/Directory/Bad/Walt/Student_Info/studentPicture1593859.png
/Directory/Bad/Jesse/Student_Info
/Directory/Bad/Hank/Student_Info/studentPicture4675935.png
/Directory/Bad/Skyler/Student_Info
/Directory/Bad/Marie/Student_Info
/Directory/Bad/Flynn/Student_Info
/Directory/Bad/Saul/Student_Info/studentPicture3984834.png

「bad」フォルダーに「HasContent」と「Empty」の 2 つのサブフォルダーを作成します。前の script . つまり、新しい分類法は次のようになります。

/Directory/Bad/HasContent/Walt/Student_Info/studentPicture1593859.png
/Directory/Bad/Empty/Jesse/Student_Info
/Directory/Bad/HasContent/Hank/Student_Info/studentPicture4675935.png
/Directory/Bad/Empty/Skyler/Student_Info
/Directory/Bad/Empty/Marie/Student_Info
/Directory/Bad/Empty/Flynn/Student_Info
/Directory/Bad/HasContent/Saul/Student_Info/studentPicture39848.png
4

2 に答える 2

1

このスクリプトを修正できました。助けてくれてありがとう、みんな!

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
于 2013-08-27T17:17:45.570 に答える
1

こんにちは、スクリプトを簡単にテストしました。また、学生情報フォルダーに複数のアイテム、フォルダー、またはファイルがある場合は、それらがカウントされます。したがって、スクリプトは壊れます。

学生情報フォルダにファイルを含むサブフォルダがあり、学生情報フォルダ自体にファイルがない場合、学生情報フォルダは空のフォルダに移動さ​​れます。

私はちょうどこれを試してみましたが、うまくいくようです。

アイデアは、学生情報フォルダーに含まれるアイテムの種類を取得することです。次に、フォルダ以外のものがないかどうかを確認します..

それ以上チェックする必要はありません。2 番目の繰り返しを終了し、必要な移動を行います。そして、最初の繰り返し内の次のフォルダーに進みます。

お役に立てれば。

    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
于 2013-08-27T23:01:13.357 に答える