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?
WellingtonISAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NVITEnd-user supportCommented:
That looks fine.
Maybe try
forfiles /m desktop.ini /p "D:\users\%username%" /s "CMD /C del @file"
0
NVITEnd-user supportCommented:
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"
0
WellingtonISAuthor Commented:
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?
0
Check Out How Miercom Evaluates Wi-Fi Security!

It's not just about Wi-Fi connectivity anymore. A wireless security breach can cost your business large amounts of time, trouble, and expense. Plus, hear first-hand from Miercom on how WatchGuard's Wi-Fi security stacks up against the competition plus a LIVE demo!

WellingtonISAuthor Commented:
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
0
Steve KnightIT ConsultancyCommented:
Try just del desktop.ini /s

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

Steve
0
Bill PrewIT / Software Engineering ConsultantCommented:
FORFILES seems like overkill for this, you should be able to just do:

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


~bp
0
NVITEnd-user supportCommented:
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

0
Bill PrewIT / Software Engineering ConsultantCommented:
Actually, these are hidden files typically, so likely need:

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

~bp
0
WellingtonISAuthor Commented:
that  maybe so however, I still need to test it somehow
0
NVITEnd-user supportCommented:
Oops. Forgot the /b switch
for /f %a in ('dir /b /ah desktop.ini') do (ECHO del /ah /q "%a")

Open in new window

0
Bill PrewIT / Software Engineering ConsultantCommented:
@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
0
WellingtonISAuthor Commented:
OK thanks!  Once I can test it I can schedule it.
0
NVITEnd-user supportCommented:
@Bill
Thanks for the reminder!
0
WellingtonISAuthor Commented:
When I run this I get this...
0
WellingtonISAuthor Commented:
0
Bill PrewIT / Software Engineering ConsultantCommented:
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
0
WellingtonISAuthor Commented:
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.
0
Bill PrewIT / Software Engineering ConsultantCommented:
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
0
NVITEnd-user supportCommented:
@WellingtonIS
Try this updated post:
for /f %a in ('dir /b /ah "desktop.ini"') do (ECHO del /ah /q "%a")
0
Bill PrewIT / Software Engineering ConsultantCommented:
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
0
WellingtonISAuthor Commented:
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"
0
NVITEnd-user supportCommented:
@Bill,
No problem. That's why I mentioned Steve's method first. Then said "If you want a more complicated method..."
0
NVITEnd-user supportCommented:
@WellingtonIS
Correction:
del d:\users /s /f /ah "desktop.ini"
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
WellingtonISAuthor Commented:
is there a way to  do a /y or all?
0
NVITEnd-user supportCommented:
@WellingtonIS
For DEL, I believe that's what the /s switch is for. It searches all subfolders.
0
WellingtonISAuthor Commented:
Thanks everyone.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Server 2008

From novice to tech pro — start learning today.