|
||||||
| General Programming Non language specific, Assembly, Linux/Unix, Mac and anything not covered in other topics. Talk about Programming Theory here. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
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 |
| Sponsored Links |
|
|
|
|||||
|
Can you post what you have, the entire batch file please?
__________________
CodeCall Blog | CodeCall Wiki | Shareware Site | Linux Forum | Write a Blog The CodeCall Wiki is now fully integrated with vBulletin users! Check it out and add some new pages! |
|
|||
|
Code:
@echo off
Echo Welcome to the Movie Batch File
:begin
echo.
echo.
ECHO Press 1 to List Last Years Major Movies
ECHO Press 2 to List Major Movies From Two Years Ago
ECHO Press 3 to List Major Movies From 3 Years Ago
ECHO Press 4 to List All Major Movies released Between 2004 and the Current Year
ECHO Press 5 to Search for a Movie Based on the First Letter
ECHO Press 6 to Quit
REM Default choice is set to Quit after a duration of 15 seconds
:begin
echo.
choice /c:123456 /n /T:6,15 Please Select an Option:
echo.
echo.
IF ERRORLEVEL == 6 GOTO QUIT
IF ERRORLEVEL == 5 GOTO BROWSE
IF ERRORLEVEL == 4 GOTO ALL
IF ERRORLEVEL == 3 GOTO THREE
IF ERRORLEVEL == 2 GOTO TWO
IF ERRORLEVEL == 1 GOTO LAST
:LAST
Echo Major Movies Released from Last Year are;
echo.
echo.
findstr /c:"2006" A:\Movie_List\List.txt >> moviesfound.txt
type moviesfound.txt
del moviesfound.txt
echo.
echo.
echo [Please Select another option]
goto :begin
:TWO
Echo Major Movies Released from Two Years Ago are;
echo.
echo.
findstr /c:"2005" A:\Movie_List\List.txt >> moviesfound.txt
type moviesfound.txt
del moviesfound.txt
echo.
echo.
echo [Please Select another option]
goto :begin
:THREE
Echo Major Movies Released from Three Years Ago are;
echo.
echo.
findstr /c:"2004" A:\Movie_List\List.txt >> moviesfound.txt
type moviesfound.txt
del moviesfound.txt
echo.
echo.
echo [Please Select another option]
goto :begin
:ALL
echo @echo off > allmovies.bat
echo echo Here are all the major movies released within the last 3 years: >> allmovies.bat
echo echo. >> allmovies.bat
echo findstr /c:"(" A:\Movie_List\List.txt >> allmovies.bat
call allmovies.bat > A:\Movie_List\allmoviesfound.txt
del allmovies.bat
echo Please check the allmoviesfound text file in A:\Movie_List
echo for a full listing
echo.
type A:\Movie_List\allmoviesfound.txt
echo.
echo.
echo [Please Select another option]
goto :begin
:BROWSE
set /P lettervar="Enter the First Letter of Movie "
if %lettervar% in (A:\Movie_List\List.txt) do findstr /b /i /c:"%lettervar%" >>
moviesfound.txt
else echo Sorry, No Movies Start with %lettervar% in the List
del moviesfound.txt
goto :begin
:QUIT
echo.
echo Thank You for using the Movie program
echo Goodbye!
|
|
|||
|
Hi. Thats the entire batch file. I want to run that variable that the user inputs and do findstr using it, and return the results with any movie that starts with the letter the user specified. I am pretty sure my syntax is wrong.
Any ideas? |
|
|||
|
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. |
| Sponsored Links |
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| File Manager | Jaan | Community Projects | 45 | 08-27-2008 12:11 PM |
| Windows XP Tricks & Tips!!!!..new ones. | pranky | Tutorials | 9 | 08-23-2008 04:22 PM |
| How to bind a file with vb | kresh7 | Visual Basic Programming | 8 | 09-28-2007 02:22 PM |
| text file manipulations in vb6.0 | Ronin_paes | Visual Basic Programming | 3 | 06-11-2007 05:54 AM |
| planning with batch file | frysay | General Programming | 3 | 05-29-2007 04:59 AM |
| WingedPanther | ........ | 2753.6 |
| Xav | ........ | 2704 |
| Brandon W | ........ | 1702.32 |
| John | ........ | 1207.73 |
| marwex89 | ........ | 1175.24 |
| morefood2001 | ........ | 966.05 |
| dcs | ........ | 655.75 |
| Steve.L | ........ | 475.59 |
| orjan | ........ | 418.58 |
| Aereshaa | ........ | 383.54 |
Goal: 100,000 Posts
Complete: 98%