Batch File help

Kelemvor

Lifer
May 23, 2002
16,928
8
81
Howdy,

I'm wondering if there's a way to make a simple batch file that can delete certain files in any user profile folders that they exist in. Basically in Windows XP, I want to go to a specific folder in C:\Docs & Settings\<user ID>\local settings.... and empty out the contents of a certain folder.

However on any given PC, there could be multiple user profile folders for whoever's machine it is. Can a batch file do advanced things like that such as going from one folder to another when we won't know what they'll be called?
 

zebano

Diamond Member
Jun 15, 2005
4,042
0
0
cd C:\Docs & Settings\%USERNAME%\local settings

environment variables are available in batch files.
 

Kelemvor

Lifer
May 23, 2002
16,928
8
81
Right but I want it to parse through ALL the various users on the PC, not just the current user.
 

MSCoder610

Senior member
Aug 17, 2004
831
0
71
Something like

FOR /F %%v in ('dir /b "C:\Documents and Settings\" ') do del C:\Documents and Settings\%%v\LocalSettings\Folder\*

Edit: %v to test at the command line, %%v in a batch file according to the FOR documentation. I'd change the 'del' command to 'echo' or something first though, to try it.
 

zebano

Diamond Member
Jun 15, 2005
4,042
0
0
Originally posted by: Kelemvor
Right but I want it to parse through ALL the various users on the PC, not just the current user.

ahh sorry I thought you meant you wanted to be sure you got the current user. MSCoders suggestino looks good.
 

Kelemvor

Lifer
May 23, 2002
16,928
8
81
Thanks. The FOR loop thing works great.

Now, is there a way to suppress error messages?

I get things like:
The system cannot find the path specified.
The process cannot access the file because it is being used by another process.

Can I get those to just not display?

EDIT: I guess for the cases where a file/folder doesn't exist, I could just embed an if statement into the FOR statement so that if it exists, then I delete it and it not it just skips it...

Not sure on the one where something else is using the file though...