|
Answer» Hi there,
I need help with some bat files please. I've got three bats that do similar but slightly different functions and what I'd like to know is if there is a way of inserting the path (in bold below) for each one, pehaps by reading something like an INI file to personalize it for the user as the path to the database will be different for each user dependent on what OS they have, and I thought it would be cool if the path could just be read from somewhere else.
eg
cd\ cd "this is the path to a database" this line starts SQLIte 3 and reads a different txt file in each bat
mtia Joe
You could have the path-to-the-database as the first line in a text file, and instead of hard coding the path in the batch file, you could read it from the text file, using set /P
Hard coded
Code: [Select]set DBPath=d:\path to\The Database\folder cd "%DBPath%" Read from file...
Contents of x:\yourpath\yourfile.txt... Code: [Select]d:\path to\The Database\folder batch file Code: [Select]set /p DBPath=<"x:\yourpath\yourfile.txt" cd "%DBPath%"thanks for the quick answer, but you've kinda confused me, have you POSTED two different options, or is it all one. I understand what you're saying about how to do it, but it's having the three different BITS in your post that are confusing me
mtia Joe
OK is this clearer...
You could have the path-to-the-database as the first line in a text file, and instead of hard coding the path in the batch file, you could read it from the text file, using set /p
METHOD (1) The way you mentioned, that is, having the path to the database folder written into the batch file. Slight change - the path is held in a variable %DBPath% - the reason why I did this will become clear below.
Code: [Select]set DBPath=d:\path to\The Database\folder cd "%DBPath%" ---- dividing line ----------------------------------------------------------------------------------------------------------------------------------------------------
Method (2) The method you asked for, reading the path name from a file...
This is the file that has one line only, which is the path to the database file. That path is a made-up example which you would need to change. So is the name of the file.
Contents of x:\yourpath\yourfile.txt... Code: [Select]d:\path to\The Database\folder THis is an example of getting the first line of a text file and putting it into a variable Code: [Select]set /p DBPath=<"x:\yourpath\yourfile.txt" cd "%DBPath%" OK, got it, I think, thanks very muchlet us know if you get it working or if you have any problems
|