Delete files from folders of multiple users at once.

I created a script to delete files from folders of multiple users at once. I am the administrator, but it cannot delete other user’s stuff. Is it possible or not?

It is… but your “usual” administrator rights will not be sufficient here. You will need higher privileges which you can get via the “do shell script” command:


on run
set file_to_delete to "/Users/bob/abx.txt"
set admin_password to "xxxxx"
do shell script (("rm -f " & file_to_delete) as text) password admin_password with administrator privileges
end run

This, for example, deletes file “abx.txt” in user bob’s home directory. “xxxxx” will be your password here.

Regards,
danB

Model: iBook g3/800 14"
Browser: Safari 312.3.3
Operating System: Mac OS X (10.3.9)

Thank you very much for your reply. It seems that I should use the do shell script command for an issue like this. As I read UNIX commands and if I haven’t missed something, rm -f deletes files and rm -d deletes folders. Is there a way to delete all the folder contents (which has both folders and files in it) without deleting the parent folder itself? If not, I’ll have to get info for every item of folder and use -d for folders and -f for files according to their classes, one by one.

This should remove all the contents from the home directory of our friend “bob” while leaving the directory itself intact:


on run
set folder_to_clean to "/Users/bob/"
set admin_password to "xxxxx"
do shell script (("cd " & folder_to_clean & " && rm -rf *") as text) password admin_password with administrator privileges
end run

Regards,
Daniel

Model: iBook g3/800 14"
Browser: Safari 312.3.3
Operating System: Mac OS X (10.3.9)

It seems that I missed something very important while reading UNIX commands; -rf :confused:

Thank you very much, it’ll be very easy by this way.