Link to home
Start Free TrialLog in
Avatar of WellingtonIS
WellingtonIS

asked on

Delete desktop.ini from user folders on a server

I'm trying to come up with a way to delete all the desktop.ini files from the user's home folders on a server.  the path is basically d:\users\%username%...  

I'm playing with this...
forfiles -p "D:\users\%username%" -s "CMD /C del Desktop.ini"

Can someone direct me?
Avatar of NVIT
NVIT
Flag of United States of America image

That looks fine.
Maybe try
forfiles /m desktop.ini /p "D:\users\%username%" /s "CMD /C del @file"
Actually... Are you, the admin, trying to delete each users desktop.ini? If so, change to:
forfiles /m desktop.ini /p "D:\users" /s "CMD /C del @file"

Still, I would test on one specific user to make sure it works. E.g.
forfiles /m desktop.ini /p "D:\users\username" /s "CMD /C del @file"
Avatar of WellingtonIS
WellingtonIS

ASKER

OK I'll try thanks the 2nd one first and if that works I'll try just the users one.
forfiles /m desktop.ini /p "D:\users" /s "CMD /C del @file"  this is look in all the folders?
I'm running the following:
forefiles.exe /m desktop.ini /p "D:\users\username"/s "CMD /C del @file"
it's listing  a bunch of stuff but not deleting the desktop.ini
Try just del desktop.ini /s

Cd /d d:\users
Del desktop.ini /s

Steve
FORFILES seems like overkill for this, you should be able to just do:

del /s /f "D:\users\%username%\desktop.ini"


~bp
Revision to Steve's:
Del desktop.ini /s /ah

Open in new window


If you want a more complicated method. hehe...

Note: This version ECHOs the command. It doesn't do the actual delete. It's for visual confirmation that the files are found. To run for real, remove the ECHO
1. Open CMD prompt to c:\users
for /f %a in ('dir /ah desktop.ini') do (ECHO del /ah /q %a)

Open in new window

SOLUTION
Avatar of Bill Prew
Bill Prew

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
that  maybe so however, I still need to test it somehow
Oops. Forgot the /b switch
for /f %a in ('dir /b /ah desktop.ini') do (ECHO del /ah /q "%a")

Open in new window

@NewVillageIT,

Just so you are aware, the /Q switch on DEL only has meaning / value when the file to be deleted contains wildcards.  For single file names, as in this case, it will have no effect.

~bp
OK thanks!  Once I can test it I can schedule it.
@Bill
Thanks for the reminder!
When I run this I get this...
No offense to NewVillageIT (I enjoy their participation on EE), but for this problem I would just use the simple DEL statement by itself and be done with it.

~bp
OK I can do that but I just want to make 100% sure it's not going to mess anything up.  I have 200 user folders on that drive and I just don't want to get into a situation where I have to restore folder because I tried something.
If you want to sort of test it do this and it will show you each file it will delete and ask if you want to delete it.

del /p /s /f /ah "D:\users\%username%\desktop.ini"

~bp
@WellingtonIS
Try this updated post:
for /f %a in ('dir /b /ah "desktop.ini"') do (ECHO del /ah /q "%a")
I guess I have to ask at this point, why are you deleting that file anyway?  It is a useful file for Windows and stores some information about the folder that contains it that can affect Windows behavior.  So if a user customized the folder icon, or some other properties of that folder they would lose those.

~bp
ok I tested this by going into the user directory
d:\users\username\ del /s /f /ah "desktop.ini"
that deleted it.  Now the last thing. Is can't I just do..

Del d:\users /s /f ah "desktop.ini"
@Bill,
No problem. That's why I mentioned Steve's method first. Then said "If you want a more complicated method..."
ASKER CERTIFIED SOLUTION
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
is there a way to  do a /y or all?
@WellingtonIS
For DEL, I believe that's what the /s switch is for. It searches all subfolders.
Thanks everyone.