# Solved: Batch File Issues



## Davecann2 (Feb 9, 2012)

Hello All,

I am a complete noob at creating batch files and can really use some help. this is what I am trying to accomplish...

Delete all XML files from a specific location within every users profile. Here is an example of my code so far...



> @echo off
> set File1="C:\Users\%UserName%\AppData\Roaming\IsolatedStorage\StrongName.g1btotwacmgxh35anhz5tuqk20pyno0a\AssemFiles\EmailContactData\*.xml"
> if exist %File1% del %File1%


... As you can see this code will only delete the files for the user that has executed the batch file. Please take note that the batch file will be executed by a domain admin and local users do not have local admin rights.


----------



## Ent (Apr 11, 2009)

I'm afraid I don't have the time to properly write such a script for you right now, but I can point you in the right direction. 

If you want to perform the same action on multiple files folders, you can use FOR. It needs the /D switch to check folders. In this case you'd be looking at using a For in C:\Users\ to check each of the user folders. For more information on that command, just type "Help For" in the command line.

If you can't get it to work, post back and I'll do what I can to cook up a fuller solution.


----------



## Davecann2 (Feb 9, 2012)

@Ent,

Thank you so much for the quick reply and for pointing me in the right direction. I will do some research and attempt to modify the code. Ill post an update on my progress by EOB today or first thing in the morning (EST). 

Best regards!


----------



## Squashman (Apr 4, 2003)

Going to assume all your users are on Windows Vista or Windows 7 otherwise you will also need to take into account the change from C:\Users and C:\Documents and Settings


----------



## Davecann2 (Feb 9, 2012)

@ Ent,
I have been beating my head trying to use the "For" loop within my batch file. Sadly, I was unsuccessful to get the file to work. Any additional feedback/snippet of code you can provide would be greatly appreciated! 

@Squashman,
Thank you for your reply to my topic. I am trying to create the batch file for both Win7 and WinXP but, to not complicate my question, I only inquired for Win7. I thought I would be able to modify the code accordingly to suite other OS's.

Any additional replies are welcome =) Any solution that can be provided is appreciated!


----------



## Ent (Apr 11, 2009)

This code prints out the names of all the folders in C:\Users


```
@echo off
CD C:\users
For /D %%F in (*) do (
echo %%~fF
)
pause
```


----------



## Davecann2 (Feb 9, 2012)

@Ent,

Thank you for providing that snippet of code. I played around with it and learned a lot. 
I will take your tips and try my best to figure this out. 

I cant say enough how much I appreciate the input you have provided. I will continue to perform more research. I think I have enough information to be able to get this batch file working.

I will post my final solution (code) once I get the batch file to run successfully. 
Cheers!


----------

