Wednesday, December 23, 2009

Batch file help advice.?

Ok, please don't think im stupid for not knowing, but im not very good with scripting and programming. I need to create a batch file to change a .txt file to something else and if that something else is already in it, to be changed back to the original: Eg.





.txt file says: My name is Bob - If it looks like this it needs to be changes to: My name is John.





And vice versa. Really need help with this. I have no experience in batch files so i know nothing about them.Batch file help advice.?
Actually, this can be done... sort of. I know how to get the first line at least.. if you need something else than that, I do not know.





The command to read a line fro ma text file into a variable is like this





set /p var= %26lt;yourfile.txt





set command sets a variable


the /p switch allows you to set the value off a variable to a line of input entered by the user.


var is the variable name; it can pretty much anything.


= is an assignment operator. ex: x=y: x is assigned the value of y.


%26lt; redirects the file contents into the assignment


yourfile.txt is the file name you are checking.





now, you can get the value of var like this


@echo offf


echo %var%





Let me know if this is even what you need, or if you need more help. I know I didn't write the whole thing, but this would really be a pain to write if it isn't the first line. Yes it is possible, but at that point, batch isn't what you should be doing this in...Batch file help advice.?
batch files can't check file text. it can only check the filename. (trust me I've tried a many a time) so if u want it 2 check filename here is a batch made by me:





@echo off


if exist ';My name is Bob.txt'; type ';My name is Bob.txt'; %26gt; ';My name is John.txt';


ping localhost -n 1 %26gt;nul


cls


EXIT

No comments:

Post a Comment