# Solved: Need a batch file to delete a specific folder in all user profiles



## techie_job

Hi, 

Facing a issue, where i need to delete a specific folder in all users profiles. 
I have been through Squash man's solution but it was more towards specific folder 
not able modify it to the requirement as i am a newbie to batch files. 

Please help 

Regards


----------



## Squashman

Well I have close to 19,000 posts on this forum so you are going to have to forgive my memory as to which thread or solution you are referring to. A link would really help. If you could supply a little more detail that would help as well. What folder and what is the path to where it is located.


----------



## techie_job

Hi Squashman,

sorry for not being detail. 
Below is the case i was referring to 
http://forums.techguy.org/dos-other/1035509-dos-batch-file-delete-certain.html

The issue is, We have an certain application folder in the below path

C:\Documents and Settings\%userprofile%\Local Settings\Application Data\appname

We are not sure which user profile has this folder "appname", so need to search in 
Documents and Settings in all user profile folders for this "appname" folder and 
delete it.

With the solution you have provided in the above URL we managed to do this for active 
profile, but need your advice how we can perform the same on all the profiles on a host.

Regards


----------



## techie_job

Squashman, 

Thanks a lot for your time and response, 
This is the solution we worked out and looks like it is working. 
Do you have any change recommendations... 

@echo off
IF EXIST "C:\Documents and Settings\" pushd "C:\Documents and Settings\"
IF EXIST "C:\Users\" pushd "C:\Users\" pushd "C:\Users\"
pushd "C:\Documents and Settings\"
for /F "tokens=*" %%I in ('dir /a:d /b /s ^| findstr "test123" ') do rmdir /q /s "%%I" 
popd

Regards


----------



## Squashman

You got two too many PUSHD commands in there.
What happens if the person has a folder named the same name in their personal documents or pictures folders. You could potentially delete a lot of documents that some one needs. You need to make sure you are deleting it from the correct path.


----------



## techie_job

so please advice how to modify to our requirement, 
as explained earlier the exact location is 
C:\Documents and Settings\%userprofile%\Local Settings\Application Data\appname 
but we need to check in all the user profiles on a host, that is where we are stuck 

Please help 

Regards


----------



## Squashman

This script will of course have to be run by a user with Administrator privileges. On Vista or 7 I cannot guarantee this will work unless executed with an elevated cmd prompt. Which basically means you would need to right click on the batch file and chose Run As Admin from the Context Menu. I don't have Windows 7 at work so I can't test it on Windows 7.


Code:


@echo off
IF EXIST "C:\Documents and Settings\" PUSHD "C:\Documents and Settings\"
IF EXIST "C:\Users\" PUSHD "C:\Users\"

FOR /F "tokens=*" %%G in ('dir /a:d-s-h /b') do (
	IF EXIST "%%G\Local Settings\Application Data\Appname" rmdir /q /s "%%G\Local Settings\Application Data\Appname"
)
POPD


----------



## techie_job

Hi Squashman, 

Thanks a lot for your advice and support, appreciate it. This solution resolved our issue. 

Regards


----------

