1.

Solve : Set name?

Answer»

Hi
im trying to use the set command to change a variable to an html code then
copy that code ONTO the file. But it has a bunch of spaces in the code and
if there are quotes around the code, it wont work.

here the code
Code: [Select]:1
set name="<html><head><title>Google</title></head><frameset cols="*" frameborder="0" border="0"><frame src="http://www.google.com/" scrolling="auto"></frameset></html>"
pause


echo %name%>%NUM%.htm
pause>nul
call %num%.htm
pause
so is there ANYWAY to set the name without using quotes so
that the code is copied onto the file as is.

Certain characters have a special meaning in batch code: */ + | \ = ? [ ] ; : " . < > ,

In order to use them, they must be escaped with a carat (^). Your code will look like hieroglyphics by the time you're done.

Example:

set name=^<html^> equates name to

You'll have to precede every special character in your string with ^

Good luck.

i tryed this:
Code: [Select]@echo off
set name=^<html^>
echo %name%
pause
but it closes the window when i run it

im using windows vista btwDid you double click your batch file or run it from the command prompt? In any case the pause statement should have held the window open until you hit a key.

You can type the set and echo statements at the command prompt to give yourself an indication of how the carat character works (that's what I did )

k i got that working but it doesnt fix my problem.
I need it to copy the html code without the quotes.
everything else is fineThe set statement does not require quotes to define the string. In fact if present, they become part of the string. If you need to keep the quotes for cols= or border= then you must escape them.

This should get you started:

set name=^<html^>^<head^>^<title^>Google^<^/title^>...

Good luck.

PS. This COULD get very messy very fast. There are many scripting languages available including VBScript and JScript which are installed with all Windows versions (except Win95A & B). Others like Python and REXX can be download free and are way better than anything batch has to offer. I just like to toss this PS. in once in a while.



Discussion

No Comment Found