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?
I'm playing with this...
forfiles -p "D:\users\%username%" -s "CMD /C del Desktop.ini"
Can someone direct me?
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"
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"
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?
forfiles /m desktop.ini /p "D:\users" /s "CMD /C del @file" this is look in all the folders?
ASKER
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
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
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%\deskt op.ini"
~bp
del /s /f "D:\users\%username%\deskt
~bp
Revision to Steve's:
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
Del desktop.ini /s /ah
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)
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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")
@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
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
ASKER
OK thanks! Once I can test it I can schedule it.
@Bill
Thanks for the reminder!
Thanks for the reminder!
ASKER
When I run this I get this...
ASKER
Here's the attachment
C--Users-wrmrosnei-Desktop-return.JPG
C--Users-wrmrosnei-Desktop-return.JPG
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
~bp
ASKER
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%\deskt op.ini"
~bp
del /p /s /f /ah "D:\users\%username%\deskt
~bp
@WellingtonIS
Try this updated post:
for /f %a in ('dir /b /ah "desktop.ini"') do (ECHO del /ah /q "%a")
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
~bp
ASKER
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"
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..."
No problem. That's why I mentioned Steve's method first. Then said "If you want a more complicated method..."
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
For DEL, I believe that's what the /s switch is for. It searches all subfolders.
ASKER
Thanks everyone.
Maybe try
forfiles /m desktop.ini /p "D:\users\%username%" /s "CMD /C del @file"