Royalaid Posted November 1, 2008 Share Posted November 1, 2008 Hey guys was just wondering if there is a way to make a batch file echo something exactly as I type it, for example echo set name=c:/%num%.bat >> %name% I get the output of set name=c:/1.bat I want it to put that exact text (set name=c:/%num%.bat) in the file not what %num% is equal to, any help is much appreciated and thanks in advance. Quote Link to comment Share on other sites More sharing options...
neXussT Posted November 1, 2008 Share Posted November 1, 2008 % and > are special characters under DOS. Escape them with a carot (^). neXussT Quote Link to comment Share on other sites More sharing options...
Royalaid Posted November 2, 2008 Author Share Posted November 2, 2008 OK, i got it to work the way i want to, kinda.... now whenever it echo's a line of text it will add the " + 1"... anyone know why this is happening? Quote Link to comment Share on other sites More sharing options...
Tarbizkit Posted November 4, 2008 Share Posted November 4, 2008 you must be doing something wrong. What neXusst said is correct the ^ character will allow you to use special characters. open a command prompt and type the following... echo set name=c:/^%num^%.bat ^>^> ^%name^% your outout should be... set name=c:/%num%.bat >> %name% Quote Link to comment Share on other sites More sharing options...
still learning Posted November 4, 2008 Share Posted November 4, 2008 if you dont want it to echo i know you put @echo off at the beginning of your batch file, so im guessing you just leave @echo off out of the batch file or put @echo on and that will do it ... not positive though Quote Link to comment Share on other sites More sharing options...
dimitar Posted November 5, 2008 Share Posted November 5, 2008 Make sure that you have @echo on at the top of the script. Then you need to put an extra % in front of each % and a ^ (caret) in front of each >. These are called "escape characters". So... your script will look like this: @echo on echo set name=c:/%%num%%.bat ^>^> %%name%% pause Quote Link to comment Share on other sites More sharing options...
neXussT Posted November 5, 2008 Share Posted November 5, 2008 The @ character turns off echoing of the command itself, so you only see the output of the command. You can affect the entire batch file by putting a "@echo off" at the beginning of the file. An example of a command in a batch file without disabling echoing: echo Hello World! The result: echo Hello World! Hello World! An example of turning off echoing for an entire batch file: @echo off echo Hello World! The result: Hello World! If you want to disable echoing for only one command, use this: @echo Hello World! --- Using "@echo off" is very standard for batch files, and you will almost never see one without it. neXussT Quote Link to comment Share on other sites More sharing options...
Royalaid Posted November 6, 2008 Author Share Posted November 6, 2008 Adding the extra percent helped fix the echo problem, and now I have the file actually working, all I need to do is make it map the C drive is there anyway that I can get the dir command to show me just files and would get the out from that be as simple as adding >> filelist.txt to the end? Quote Link to comment Share on other sites More sharing options...
neXussT Posted November 6, 2008 Share Posted November 6, 2008 Type "DIR /?" for information on the DIR commands paramaters If you want a list of files in the current directory without listing the directory, type this: DIR /a-d If you want to get rid of the file information, type this: DIR /b/a-d If you want a list of all the files in the current directory and subdirectories without listing the directories, type this: DIR /s/b/a-d You can learn a lot by typing the following commands: SET /? DIR /? FOR /? HELP neXussT Quote Link to comment Share on other sites More sharing options...
Royalaid Posted November 8, 2008 Author Share Posted November 8, 2008 Thanks neXussT for all your help and sorry about my inability to use intelligent grammar while typing... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.