Let’s assume that your Pictures folder is located on your desktop and the Categories folder is located inside of the pictures folder. AssumingAssuming that all of the picture files are located in the Pictures folder, this following AppleScript code should work.
Paste this following code into a new Script Editor.app document. You can run the code directly from that document or you can save the code as an application and run the application like you would with any other app.
propertyset picturesFolder : (path to desktopchoose folder aswith text)prompt &¬
"Pictures" as alias
property categoriesFolder"Choose :The (pathFolder Containing Your Pictures" with invisibles
set categoriesFolder to desktopchoose folder aswith text)prompt &¬
"Pictures:Categories" as alias "Choose The Categories Folder" with invisibles
tell application "Finder"
activate
set pictureFiles to files of picturesFolder as alias list
repeat with i from 1 to count of pictureFiles
set foldersRef to (a reference to folders of categoriesFolder)
set foldersRefItems to name of (contents of foldersRef)
set thisItem to item i of pictureFiles
set fileName to (text items 1 thru -5) of (name of thisItem as text) as string
if fileName is not in foldersRefItems then
duplicate thisItem to (make new folder at categoriesFolder ¬
with properties {name:fileName})
else
duplicate thisItem to folder fileName of categoriesFolder
end if
end repeat
end tell