Al Lelopath
Al Lelopath

Reputation: 6778

Suppress error output (sometimes) in batch file

I am writing a batch file to delete all network mappings and then remap. In the first section where any current mappings are deleted, if a mapping does not exist and it tries to delete it, it outputs an error message "The network path was not found". I don't want to see these, but then I do want to see any errors that occur in the second part where it does the mapping. How do I do this?

echo delete all mappings

net use A: /delete
net use B: /delete
net use C: /delete
net use D: /delete
net use E: /delete
net use F: /delete
net use G: /delete
net use H: /delete
net use I: /delete
net use J: /delete
net use K: /delete
net use L: /delete
net use M: /delete
net use N: /delete
net use O: /delete
net use P: /delete
net use Q: /delete
net use R: /delete
net use S: /delete
net use T: /delete
net use U: /delete
net use V: /delete
net use W: /delete
net use X: /delete
net use Y: /delete
net use Z: /delete

echo set mappings

net use G: \\mynetw-nas\GIS1
net use I: \\mynetw-nas\ITO

Upvotes: 0

Views: 1026

Answers (2)

Stephan
Stephan

Reputation: 56228

why iterate through 26 letters?

net use * /delete /y

NOTE: to try it out, use it without /y - then there is a security (Y/N) prompt

Upvotes: 1

Dennis van Gils
Dennis van Gils

Reputation: 3471

You can use this:

echo delete all mappings

2>nul (net use A: /delete
net use B: /delete
net use C: /delete
etc...)

echo set mappings

net use G: \\mynetw-nas\GIS1
net use I: \\mynetw-nas\ITO

note that 2>nul redirects error output to prevent it from showing

Upvotes: 2

Related Questions