![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Nov 2007
Posts: 4
Rep Power: 0
![]() |
I have tried.. but I just can't get this
Hi. I have been trying to write this batch file (command prompt. bat file) for days now. It is due tomorrow. I am taking a degree in Computer Networking and We got asked to write a batch file. I cannot grasp computer syntax, I just find programming so difficult. I, have however, after so many hours, cans of red bull, stress, close to giving up, wrote a batch file that meets the criteria of whats been asked. All that is left now is for me to include FOR and IF into my program. Basically, my batch file Has 6 ERRORLEVELS, the 6th being quit, and 1 through 4 display a movie from a certain year simply using the findstr command. I have been trying for 8 hours to try and get my 5th errorlevel functioning. What I need it to do is Ask the User for Input. Basically saying "Please Enter A letter between A and Z to search through the list of movies". I have the list of movies sitting on my Floppy Disk, there is the title and then in brackets the year. So basically
Beautiful Boxer (2005) Moonshine (2006) ^^ that is a small part of my List.txt. The code I have right now is :BROWSE Echo Enter Letter to search movie starting with that letter: %%i for %%i in (A:\Movie_List\List.txt) do findstr /b /i /c:"%%i" >> moviesfound.txt if not errorlevel=1 (type moviesfound.txt) else echo Sorry, No Movies Start with %%i in the List del moviesfound.txt goto :begin In my findstr I have put /b so that is searches for the start of the text. Therefore I will get movies starting with that letter. So when My user enters the letter, it outputs the results to a file called moviesfound.txt, and then I am showing the contents of that file I have written to in my batch file. Please Guys, I know it says you should try yourself before asking homework questions, but I have tried so hard. I just don't know how to do this. Do I need the Set /p? I just need the user to enter some sort of temporary variable, then that variable to be searched for in findstr. Thanks ![]() |
|
|
|
|
|
#2 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Re: I have tried.. but I just can't get this
Have you considered telling us how your attempts fail to meet your expectations, or shall we pull some stuff out of our butts and guess?
Remember, we're not going to benefit from your grade. Tell us something useful.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#3 | |
|
Newbie
Join Date: Nov 2007
Posts: 4
Rep Power: 0
![]() |
Re: I have tried.. but I just can't get this
Quote:
Ok, well, :BROWSE Echo Enter Letter to search movie starting with that letter: %%i for %%i in (A:\Movie_List\List.txt) do findstr /b /i /c:"%%i" >> moviesfound.txt if not errorlevel=1 (type moviesfound.txt) else echo Sorry, No Movies Start with %%i in the List del moviesfound.txt goto :begin What I am getting here When I run this Errorlevel is "Enter Letter to search movie starting with that letter: %1". Then nothing. I cant exit the program, I cant get back to the main menu. It just allows me to enter letters, and nothing happens. My expections is to have an Echo saying "Please Enter the letter" then somehow (and it is this part that confuses me most) I want to take that input, store it in a variable, and put that variable into findstr, where I can return the results of the movies based on the letter. So the user enters "C" they will get every result that starts with C. |
|
|
|
|
|
|
#4 |
|
Newbie
Join Date: Nov 2007
Posts: 4
Rep Power: 0
![]() |
Re: I have tried.. but I just can't get this
:BROWSE set /P lettervar="Enter the First Letter of Movie " for %lettervar% in (A:\Movie_List\List.txt) do findstr /b /i /c:"%lettervar%" >> moviesfound.txt if not errorlevel=1 (type moviesfound.txt) else echo Sorry, No Movies Start with %lettervar% in the List del moviesfound.txt goto :begin Am I getting closer? Can you see What I am trying to achieve here? I want the users input to be stored in this variable and then have the variable searched for in the List.txt. When I ran the program I was able to enter a letter, but then my file closes it self. |
|
|
|
|
|
#5 |
|
Newbie
Join Date: Nov 2007
Posts: 4
Rep Power: 0
![]() |
Re: I have tried.. but I just can't get this
ok I got it working using...
:BROWSE Echo %1 will be searched... echo. for %%i in (.\Movie_List\List.txt) do findstr /b /i /c:"%1" %%i >> moviesfound.txt if not errorlevel=1 (type moviesfound.txt) else echo There are no movies that start with letter '%1' del moviesfound.txt goto :begin I don't know how u guys do this programming/scripting. It's rocket science to me. I hope I never need to do another one of these. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|