Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 15th, 2007, 3:31 PM   #1
ineedofhelp
Newbie
 
Join Date: Nov 2007
Posts: 4
Rep Power: 0 ineedofhelp is on a distinguished road
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
ineedofhelp is offline   Reply With Quote
Old Nov 15th, 2007, 3:38 PM   #2
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
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
DaWei is offline   Reply With Quote
Old Nov 15th, 2007, 3:49 PM   #3
ineedofhelp
Newbie
 
Join Date: Nov 2007
Posts: 4
Rep Power: 0 ineedofhelp is on a distinguished road
Re: I have tried.. but I just can't get this

Quote:
Originally Posted by DaWei View Post
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.

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.
ineedofhelp is offline   Reply With Quote
Old Nov 15th, 2007, 4:06 PM   #4
ineedofhelp
Newbie
 
Join Date: Nov 2007
Posts: 4
Rep Power: 0 ineedofhelp is on a distinguished road
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.
ineedofhelp is offline   Reply With Quote
Old Nov 15th, 2007, 7:06 PM   #5
ineedofhelp
Newbie
 
Join Date: Nov 2007
Posts: 4
Rep Power: 0 ineedofhelp is on a distinguished road
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.
ineedofhelp is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:17 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC