As a starting point you may use :
tell application "Finder"
set selected to selection
set current_folder to item 1 of selected
set mlist to every file of current_folder
set x to mlist
repeat with i from 1 to the count of x
set this_file to item i of x
if i is not 1 then
set previous_file to item (i - 1) of x
set prev_ext to cur_ext
set prev_name to new_name
else
set prev_name to ""
end if
set cur_ext to name extension of this_file
set new_name to text 1 thru -((length of cur_ext) + 2) of (name of this_file as text)
if new_name is not equal to prev_name then
set new_folder to make new folder with properties {name:new_name} at current_folder
set subfolderLevel1 to make new folder at new_folder with properties {name:"level 1"}
set subfolderLevel2 to make new folder at subfolderLevel1 with properties {name:"level 2"}
end if
move this_file to new_folder
# Add instructions moving wanted files in subfolders
end repeat
end tell
When I ran it I got the arborescence :
HTG101_100_001
HTG101_100_001.mov
level 1
level 2
HTG101_100_025
HTG101_100_025.mov
level 1
level 2
If it really does what you want, I will edit it to no longer use the Finder which I hate.
Yvan KOENIG running Sierra 10.12.6 in French (VALLAURIS, France) mercredi 26 juillet 2017 11:31:40