Hey all, I need some help with my batch file that i'm creating for myself. So a bit of background for this;
I'm making a .bat "Archiver" that stores CD Keys that belong to software/games. I have it setup pretty great and figured stuff out, but this one thing I do not get.
Basically I have three options in the menu
#1 add a cd key
#2 look up a cd key
#3 edit a cd key
so #1 I have the input like this:
set /p %name%= Please enter name:
set /p %key%= Please enter key:
echo %name%, %key% > %name%.txt
So whatever name they type in is dubbed the %name% variable. Whatever key they type in, is dubbed the %key% variable. Both are saved to a %name%.txt file; so that %name%.txt will be starcraft.txt or whatever name they typed in.
So, going to #2, it only displays the .txt file (via type command) after you just added it. Only then can you bring up the name and cd key. When you close the batch file and start it back up again, it can't find the file. So i dont know if I need to have some sort of memory code or something to save it?
Anyways, here #2's code:
set /p %name%= please enter name you wish to look up:
[then a bunch of timed echo stuff to make it look cool]
type %name%.txt
So, like I was saying before, it will display the %name% and cd %key% within the %name%.txt file as long as you don't close out the batch file, if you store you cd key, look it up (it will display) and then close it, and try to do it again, it wont be able to find the file.
What gives?
:-/
i'm a new guy here, and still remembering how to make batch files.
Thanks guys!
Need help with batch program please
Moderator: DosItHelp
-
- Expert
- Posts: 1167
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
Re: Need help with batch program please
Does the file exist if you navigate to where it should be?
Re: Need help with batch program please
Yes, the %name%.txt files are created in the same folder that the batch file is in. When I have both the folder and the batch file open, once I've done added the name and cd key it appears right away in the folder and stays there till its deleted.
Thanks for replying
Thanks for replying

Re: Need help with batch program please
The batch file will find them if it is launched in the same folder.
This will allow you to use spaces in a filename. Add the quotes here and when saving.
type "%name%.txt"
This will allow you to use spaces in a filename. Add the quotes here and when saving.
type "%name%.txt"
Re: Need help with batch program please
That's exactly what I had. But I fixed it lol I figured out what was wrong with it
Instead of "set /p %name%= Please enter name"
It needed to be "set /p name= Please enter name"
and the type stayed the same; "type" %name%.txt"
Instead of "set /p %name%= Please enter name"
It needed to be "set /p name= Please enter name"
and the type stayed the same; "type" %name%.txt"
Re: Need help with batch program please
Well spotted.
If you use the actual quotes as listed below then you can use more than one word in the variable as well as characters like an &
If you use the actual quotes as listed below then you can use more than one word in the variable as well as characters like an &
Code: Select all
set /p "name=Please enter name: "
set /p "key= Please enter key: "
for /f "delims=" %%a in ("%name%, %key%") do >"%name%.txt" echo %%a