Link to home
Start Free TrialLog in
Avatar of yuhs
yuhs

asked on

What script syntax to delete a file from all of the \\Documents and Settings desktops?

VERY simple script, but I can't figure it out.

I want to deploy a script to my building to delete a particular icon from all the user desktops (XP machines). The icon I want to delete is not in the "All Users" profile, but is saved in individual user profiles. This script below works when I use it to delete the icon from the All Users, Default User, or my own desktop. But how do I script it to delete the icon from all the unknown profiles on the PC ?

This works:    del icon.url "\\%PC%\C$\Documents and Settings\all users\Desktop"
This doesn't:  del icon.url "\\%PC%\C$\Documents and Settings\%users%\Desktop"
Avatar of Shift-3
Shift-3
Flag of United States of America image

You can use FOR /F to loop through subfolders of the Documents and Settings folder, as in the code below.  Change all instances of %%G to %G if you're running it from the command line rather than in a batch script.

See here for a good explanation of FOR /F:
http://www.ss64.com/nt/for_cmd.html


for /F "tokens=* usebackq" %%G in (`dir "\\%PC%\C$\Documents and Settings" /A:D /B`) do (
 del "\\%PC%\C$\Documents and Settings\%%G\Desktop\icon.url"
)

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of knightEknight
knightEknight
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
^ ... even if icon.url does not exist in the "Documents and Settings" folder, but only it its sub-folders, the command above will delete this file from all the sub-folders.