change owner of files in a folder recursively

I’d like to have a path to a folder and change all the files underneath the folder to the current logged in user account. Something like this:

try
do shell script “pathname=/Applications/DTIApps ; currentuser=/usr/bin/whoami ; chmod -R $currentuser $pathname”
end try

I can run this without errors, but it doesn’t change the permissions?
thanks for your help!

If you don’t own the files you can’t change their owner. Clearly you don’t own the files otherwise you wouldn’t need to run this script.

The solution is to run the shell script with elevated privileges (e.g. root) so that you can change the ownership of other user’s files. The standard way of doing this is:

do shell script "blah; blah; blah" with administrator privileges

The ‘with administrator privileges’ will authenticate the user and then use sudo to execute the command as root.