Computing.Net > Forums > Programming > Need batch that does 5 things

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Need batch that does 5 things

Reply to Message Icon

Name: love2program
Date: March 15, 2009 at 15:46:09 Pacific
OS: Windows Vista
Subcategory: Batch
Comment:

Hi, I need a batch file that 1. gives me a menu
with choices to:
1. print todays date
2. clear files
3. clear archive
4. get news
5. exit
for choice 1 i want the output to be the name
of the month not the numerical value so
something like today is Tuesday march 15,
2009
for choice 2 I want it to ask the user what
directory to clear and provide a prompt saying
are you sure? before deleting files.
for choice 3 I want to be able to clear the
archive attribute from all files in a given
directory. I want to be prompted for which
directory to act on.
for choice 4 I want it to display a secondary
menu that selects from: www.cnn.com,
www.weather.com, or www.msn.com. I want to
launch the browser on the choice chosen.

This is what I have written so far:

echo off

:menu
cls
if '%1%'=='' ( echo 1. print today's date )
if '%2%'=='' ( echo 2. clear files )
if '%3%'=='' ( echo 3. clear archive )
if '%4%'=='' ( echo 4. get news )
echo 5. Exit
set choice=
set /p choice="Please select a number ( 1-5 )
and press enter: "

if '%choice%'=='' goto menu
if '%choice%'=='1' goto first
if '%choice%'=='2' goto second
if '%choice%'=='3' goto third
if '%choice%'=='4' goto forth
if '%choice%'=='5' goto fith
cls
goto menu

:first
set choice=
set /p choice= %date:~-10,-8% please type
the 2 digit number seen:
if '%choice%'=='01' echo today is January
if '%choice%'=='02' echo today is Febuary
if '%choice%'=='03' echo today is March
if '%choice%'=='04' echo today is April
if '%choice%'=='05' echo today is May
if '%choice%'=='06' echo today is June
if '%choice%'=='07' echo today is July
if '%choice%'=='08' echo today is August
if '%choice%'=='09' echo today is September
if '%choice%'=='10' echo today is October
if '%choice%'=='11' echo today is November
if '%choice%'=='12' echo today is December
date /t
pause
goto menu

:second

:third


:forth
echo 1. www.cnn.com
echo 2. www. weather.com
echo 3. www.msn.com
echo 4. Exit to menu
set choice=
set /p choice="Select where to get your news
from (1-3): "

if '%choice%'=='' goto forth
if '%choice%'=='1' start www.cnn.com
if '%choice%'=='2' start www.weather.com
if '%choice%'=='3' start www.msn.com
if '%choice%'=='4' goto menu
cls
goto forth

:fith
set choice=
set /p choice="Are you sure you want to exit?
y/n: "

if '%choice%'=='' goto fith
if '%choice%'=='y' goto end
if '%choice%'=='n' goto menu
cls
goto fith

:end
/pre>

the date thing for section 1 doesn't work and
i'm not really sure how to get it to same for
section 2 and 3 if anyone has any idea how to
do it it would be greatly appreciated. Thanks.



Sponsored Link
Ads by Google

Response Number 1
Name: Holla
Date: March 16, 2009 at 02:01:44 Pacific
Reply:

love2,

Try this and let us know:
Change these lines:
:first
set choice=
set /p choice= %date:~-10,-8% please type
the 2 digit number seen:
if '%choice%'=='01' echo today is January

to

set choice=
set choice=%date:~-10,-8%
if "%choice%"=="01" echo today is January

:and so on for other months.. that is to remove single quotes and replace it by double quotes.

--
Holla.


0

Response Number 2
Name: love2program
Date: March 16, 2009 at 07:20:08 Pacific
Reply:

ok but for the date section I dont want to be prompted to get the month name I would like it to just do it. If thats possible? Let me know if you know how to do that or the rest. Thanks!


0

Response Number 3
Name: Holla
Date: March 16, 2009 at 09:13:55 Pacific
Reply:

love2,

1. Have you tried what I suggested?
2. Does it prompt for the month number?

--
Holla.


0

Response Number 4
Name: love2program
Date: March 16, 2009 at 11:03:58 Pacific
Reply:

ya I think I figured out the date thing I changed it to

:first
set month= % date:~-10,-8%
for /f "eol=; tokens=%month% delims=," %%i in ("January,Febuary,March,April,May,June,July,August,September,October,November,December") do set month %%i && echo %%i

this gives me the output in month so March instead of 03

I still need help on part 2 and 3 though if you have any ideas


0

Response Number 5
Name: Holla
Date: March 17, 2009 at 10:44:51 Pacific
Reply:

love2,
for part 2,
set /p dir2clear=What dir?
set /p Confirm=Are u sure to delete %dir2clear%
if not exist %dir2clear% goto :NoDir
cd %dir2clear%
:well, you know the rest.
:NoDir
echo Dir %dir2clear% does not exist.

For part 3,
the above and use attrib command.
type "attrib /?" to get help on attrib.

--
Holla.


0

Related Posts

See More



Response Number 6
Name: love2program
Date: March 17, 2009 at 13:03:08 Pacific
Reply:

Ok thanks got everything working perfectly now!


0

Sponsored Link
Ads by Google
Reply to Message Icon

Perl script help batch file if help



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Need batch that does 5 things

Need Batch File for CSV file www.computing.net/answers/programming/need-batch-file-for-csv-file/16278.html

Need batch file to delete old files www.computing.net/answers/programming/need-batch-file-to-delete-old-files/14092.html

Batch that grabs a random line? www.computing.net/answers/programming/batch-that-grabs-a-random-line/16888.html