Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

Batch file having an issue with "&"

Avatar of Simon336697
Simon336697Flag for Australia asked on
Windows BatchVB Script
8 Comments1 Solution417 ViewsLast Modified:
Hi guys,
Im having a slight problem with a batch file.
It is having issues with lines in a text file that it acts against (groups.txt) where the lines have an "&" in the line.
For these lines, i get an error like the following:

eg. the following is the line in groups.txt which is "TESTING R&C GLO"

Processing TESTING R   <-- see how it has trouble reading the "& as in R&C GLO
"C is not recognized as an internal or external command, operable program or batch file."

The script continues though.
I just dont want to see these error messages.

Here is the batch file in the code snippet.

When the batch file creates a file for each group, it returns the usernames correctly, but the filenames are wrong, that is....it creates the filenames but does not include the "&" and everything following it.
Basically,
1) I want to avoid the errors when running the batch file from a command line
2) I want the & to be includes as part of the filename
3) I dont know why when i run the batch file, that the script has an issue with lines having "&".

Any help greatly appreciated.

@echo off
setlocal
set InputFile=groups.txt
for /f "delims=" %%a in ('type "%InputFile%"') do (
  set Group=%%~a
  call :process
)
echo Done.
goto :eof
 
:process
echo Processing %Group% ...
set GroupFile=%Group%.txt
if exist "%GroupFile%" del "%GroupFile%"
for /f "tokens=2 delims=,=" %%a in ('dsquery group -name "%Group%" ^| dsget group -members') do (
  >>"%GroupFile%" echo %%a
)
goto :eof
ASKER CERTIFIED SOLUTION
Avatar of ChristopherDunn
ChristopherDunn

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Commented:
This problem has been solved!
Unlock 1 Answer and 8 Comments.
See Answers