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?
 
NVITCommented:
@WellingtonIS
Correction:
del d:\users /s /f /ah "desktop.ini"
0
 
NVITCommented:
That looks fine.
Maybe try
forfiles /m desktop.ini /p "D:\users\%username%" /s "CMD /C del @file"
0
 
NVITCommented:
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
Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

 
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
 
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 PrewCommented:
FORFILES seems like overkill for this, you should be able to just do:

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


~bp
0
 
NVITCommented:
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 PrewCommented:
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
 
NVITCommented:
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 PrewCommented:
@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
 
NVITCommented:
@Bill
Thanks for the reminder!
0
 
WellingtonISAuthor Commented:
When I run this I get this...
0
 
WellingtonISAuthor Commented:
0
 
Bill PrewCommented:
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 PrewCommented:
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
 
NVITCommented:
@WellingtonIS
Try this updated post:
for /f %a in ('dir /b /ah "desktop.ini"') do (ECHO del /ah /q "%a")
0
 
Bill PrewCommented:
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
 
NVITCommented:
@Bill,
No problem. That's why I mentioned Steve's method first. Then said "If you want a more complicated method..."
0
 
WellingtonISAuthor Commented:
is there a way to  do a /y or all?
0
 
NVITCommented:
@WellingtonIS
For DEL, I believe that's what the /s switch is for. It searches all subfolders.
0
 
WellingtonISAuthor Commented:
Thanks everyone.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.