set sourceFolder to choose folder
--set sourcefolder to (path to desktop as text) & "formoosmahna:" as alias
--set keyName to "staff_01"
set keyName to text returned of (display dialog "Type a folder name" default answer "Staff_01")
tell application "System Events"
set theSubFolders to folders of sourceFolder
repeat with aSubfolder in theSubFolders
set itsFiles to (files of aSubfolder whose visible is true)
if itsFiles is not {} then
set movableFiles to {}
repeat with aFile in itsFiles
if name of aFile contains keyName then set end of movableFiles to contents of aFile
end repeat
if movableFiles is not {} then
set dest to (path of aSubfolder as text) & keyName & ":"
if not (exists folder dest) then
make new folder at end of aSubfolder with properties {name:keyName}
end if
set posixDest to my quoteIt(dest)
repeat with aFile in movableFiles
set qSource to my quotePOSIXit(path of aFile)
do shell script "mv " & qSource & space & posixDest
end repeat
end if
end if
end repeat
end tell # System Events
on quotePOSIXit(aPath) # really useful for the POSIX part
return quoted form of POSIX path of aPath
end quotePOSIXit
Yvan KOENIG running El Capitan 10.11.2 in French (VALLAURIS, France) mercredi 9 décembre 2015 19:28:19