Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

y/n question

31 views
Skip to first unread message

rachel

unread,
Aug 15, 2002, 6:58:25 PM8/15/02
to
Hi.

I want to copy files to the floppy like this:

Ask user if they want data to be copied to the floppy with a y/n question
If no end batch
If yes then copy files and return to the question above.

I've been looking all day for this info. I'm thinking its probably so basic
no FAQ ever mentions it.

Thanks!

Rachel


Phil Robyn

unread,
Aug 15, 2002, 7:07:46 PM8/15/02
to

So which version of NT (4.0, Win2000, WinXP) do you want to do this in?

--
t o s e n d e - m a i l u s e ' R e p l y - T o '
o r u n z i p m y ' F r o m ' a d d r e s s ....

rachel

unread,
Aug 15, 2002, 9:36:55 PM8/15/02
to
Yah I did leave that out. But I didn't give up and I found that choice.exe
in the windows2000 resource kit, and spend several hours writing the
following: http://junk.directivex.com/howto/moms-batch2.txt (it uses 3rd
party tools: xxcopy, now, zip, and choice of course).

What took most my time was figuring out that the "IF ERRORLEVEL..." requires
the last option listed 1st.

Rachel


"Phil Robyn" <zipp...@uclink.berkeley.edu> wrote in message
news:3D5C3442...@uclink.berkeley.edu...
[snip]


> So which version of NT (4.0, Win2000, WinXP) do you want to do this in?

[snip]


rachel

unread,
Aug 15, 2002, 10:09:05 PM8/15/02
to
now.exe that I use is not the ms version. this version allows me to create a
file or directory oh the current time. it's a great tool, but it's 16-bit. i
wish i had a 32-bit version, but i have never found one. maybe there is a
way to do that in the batch itself?

rach


Phil Robyn

unread,
Aug 16, 2002, 12:30:18 AM8/16/02
to

There probably is, although it is not entirely clear from
your message

> file or directory oh the current time. . . .

exactly what is being done. Are you creating a file or
directory whose *name* contains the current (date and)
time, or a file whose *contents* consist of the current
(date and) time, or what????


--
U s e ' R e p l y - T o ' a d d r e s s o r
u n z i p ' F r o m ' t o s e n d m a i l

Garry Deane

unread,
Aug 16, 2002, 12:52:49 AM8/16/02
to
On Thu, 15 Aug 2002 19:09:05 -0700, "rachel" <ldfkg...@sldfldsk.net>
wrote:

Yes, it can be done in batch. I'm not sure of the fields that NOW
produces but it looks like you are using the month (word), the day of
the month (numeric) and the hour of the day (numeric). The code below
will produce that or can be adjusted as required for similar results.

A couple of other points:

Since you're using W2k, you can just as easily use SET /p instead of
CHOICE. The only difference is that you need to press <return> after
the y/n reply.

@echo off
echo Would you like to back up that
set /p choice="data to the floppy? (y/n): "
if /i "%choice%" == "y" (goto floppy-write) else goto end

Also, since you're using Xxcopy, you can use the date and time macros
in Xxcopy to create the directories without the need for the extra
date/time batch code e.g.

xxcopy sourcepath\ destpath\/$mondd$_/$hh$\

will automatically create and copy your source data to a directory
called destpath\Aug16_12\ or whatever is the current date/time.

Garry

Date/Time batch code follows:

@echo off
setlocal
call :get_date
call :get_time
set /a tok=1%mm%-100
for /f "tokens=%tok%" %%a in (
"Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec") do set mon=%%a
set dest=%mon%%dd%_%hh%
echo Destination name is: %dest%
goto :eof

:: ------------------------------------------------------------------
:Get_Date
:: ------------------------------------------------------------------
:: Generic date parser
:: Sets %dd% (01-31), %mm% (01-12) & %yy% (2 or 4 digit)

if "%date%A" LSS "A" (set toks=1-3) else (set toks=2-4)
for /f "skip=1 tokens=2-4 delims=(-)" %%a in ('echo:^|date') do (
for /f "tokens=%toks% delims=.-/ " %%d in ('date/t') do (
set %%a=%%d
set %%b=%%e
set %%c=%%f
set toks=
)
)
goto :eof

:: ------------------------------------------------------------------
:Get_Time
:: ------------------------------------------------------------------
:: Generic time parser
:: Returns time elements as 2 digit values (24 hr clock)
for /f "tokens=5-8 delims=:., " %%a in ('echo:^|time') do (
set hh=%%a
set mn=%%b
set ss=%%c
set ds=%%d
)
if %hh% LSS 10 set hh=0%hh%
goto :eof

ray

unread,
Aug 16, 2002, 12:20:38 PM8/16/02
to

I got "addicted" to now.exe but I realize I can't distribute
it - it's part of the MS Reskit.

So... using batch and vbscript I wrote my own. It's kind
of ugly, but it works and it's now a self-contained batch file
that emulates the output from now.exe. It also extracts a
bunch of variables, such as month, day, etc...

If you wanted to do it in batch, there's a way to do it using
the prompt $T $D stuff and extracting that...

some lines are long and may be wrapped (I tried to note that)

@ECHO %0 version 3.0
@Echo Off
set rnd=%Random%

Echo Mon=Left(MonthName(Month(now),1),3) > %temp%\x%rnd%.vbs
::the following line is wrapped
Echo wscript.echo (WeekdayName(weekday(now),1) ^&" "^& Mon ^&" "^&
Day(now) ^& _ >> %temp%\x%rnd%.vbs
::the following line is wrapped
Echo " "^& Hour(now) ^&":"^& Minute(now) ^&":"^& Second(Now) ^&" "^&
Year(Now)) >> %temp%\x%rnd%.vbs
cscript //nologo %temp%\x%rnd%.vbs > %temp%\x%rnd%%rnd%.txt
FOR /f "tokens=1" %%A in (%temp%\x%rnd%%rnd%.txt) do SET DayOfWeek=%%A
FOR /f "tokens=2" %%A in (%temp%\x%rnd%%rnd%.txt) do SET Month=%%A
FOR /f "tokens=3" %%A in (%temp%\x%rnd%%rnd%.txt) do SET D2=%%A
Set D2=0%d2%
Set Day=%D2:~-2%
if "%day%" == "" set Day=%D2%
Set D2=
FOR /f "tokens=5" %%A in (%temp%\x%rnd%%rnd%.txt) do SET Year=%%A
set Y2KYear=%Year%
set year=%year:~2,2%
FOR /f "tokens=4" %%A in (%temp%\x%rnd%%rnd%.txt) do SET Time=%%A
FOR /f "tokens=1 delims=:" %%A in ("%Time%") do set H2=%%A
Set H2=0%H2%
Set Hour=%H2:~-2%
if "%Hour%" == "" set Hour=%H2%
Set H2=
FOR /f "tokens=2 delims=:" %%A in ("%Time%") do set M2=%%A
Set M2=0%M2%
Set Min=%M2:~-2%
if "%Min%" == "" set Min=%M2%
Set M2=
if /i "%MONTH%"=="Jan" set MonthNumeric=01
if /i "%MONTH%"=="Feb" set MonthNumeric=02
if /i "%MONTH%"=="Mar" set MonthNumeric=03
if /i "%MONTH%"=="Apr" set MonthNumeric=04
if /i "%MONTH%"=="May" set MonthNumeric=05
if /i "%MONTH%"=="Jun" set MonthNumeric=06
if /i "%MONTH%"=="Jul" set MonthNumeric=07
if /i "%MONTH%"=="Aug" set MonthNumeric=08
if /i "%MONTH%"=="Sep" set MonthNumeric=09
if /i "%MONTH%"=="Oct" set MonthNumeric=10
if /i "%MONTH%"=="Nov" set MonthNumeric=11
if /i "%MONTH%"=="Dec" set MonthNumeric=12
del %temp%\x%rnd%.vbs
del %temp%\x%rnd%%rnd%.txt
set rnd=
set Time=

Ray

Phil Robyn

unread,
Aug 16, 2002, 1:04:32 PM8/16/02
to

C:\cmd>now Here is my message...

Fri Aug 16 10:01:35 2002 -- Here is my message...

C:\cmd>xnow Here is my message...
Fri Aug 16 10:01:37 2002 -- Here is my message...

C:\cmd>rlist util\xnow.cmd
=====begin C:\cmd\util\xnow.cmd====================
01. @echo off
02. ::
03. :: replacement for NOW.EXE from the Resource Kit
04. ::
05. setlocal
06. for /f "tokens=*" %%a in (
07. 'echo.^|time ^|findstr "current"'
08. ) do set ztime=%%a
09. set ztime=%ztime:~21,8%
10. if "%ztime:~0,1%" EQU " " set ztime=0%ztime:~1%
11. for /f "tokens=1-4 delims=/ " %%a in ('date /t') do (
12. set DAY=%%a&set MM=%%b& set DD=%%c& set YYYY=%%d)
13. if %MM% LSS 10 set MM=%MM:~1%
14. for /f "tokens=%MM%" %%a in (
15. 'echo Jan Feb Mar Apr May Jun Jul Aug Sep Nov Oct Nov Dec') do (
16. set result=%DAY% %%a %DD% %ztime% %YYYY%)
17. if [%1] NEQ [] set result=%result% -- %*
18. endlocal&echo %result%
=====end C:\cmd\util\xnow.cmd====================

ray

unread,
Aug 16, 2002, 2:09:26 PM8/16/02
to
Phil Robyn wrote:
> 11. for /f "tokens=1-4 delims=/ " %%a in ('date /t') do (
> 12. set DAY=%%a&set MM=%%b& set DD=%%c& set YYYY=%%d)
> 13. if %MM% LSS 10 set MM=%MM:~1%
> 14. for /f "tokens=%MM%" %%a in (
> 15. 'echo Jan Feb Mar Apr May Jun Jul Aug Sep Nov Oct Nov Dec') do (
> 16. set result=%DAY% %%a %DD% %ztime% %YYYY%)
> 17. if [%1] NEQ [] set result=%result% -- %*
> 18. endlocal&echo %result%
> =====end C:\cmd\util\xnow.cmd====================

Phil, what about changing regional settings?
On my W2K machine, Date/t gives me:

N:\>date /t
Fri 2002-08-16

I prefer YMD as my date format using - instead of /.

That's why I ended up using vbscript to get the date from the
windows API - because is 01-02-03 January 2, 2003 (MDY)
or February 3, 2001? (YMD)

I guess if you hated vbscript you could use regedit to
extract the regkey for the regional settings, but that's
a lot of work.

Ray

Phil Robyn

unread,
Aug 16, 2002, 2:19:49 PM8/16/02
to
ray wrote:
> Phil Robyn wrote:
>
>> 11. for /f "tokens=1-4 delims=/ " %%a in ('date /t') do (

11. for /f "tokens=1-4 delims=- " %%a in ('date /t') do (

>> 12. set DAY=%%a&set MM=%%b& set DD=%%c& set YYYY=%%d)

12. set DAY=%%a&set MM=%%c& set DD=%%d& set YYYY=%%b)

>> 13. if %MM% LSS 10 set MM=%MM:~1%
>> 14. for /f "tokens=%MM%" %%a in (
>> 15. 'echo Jan Feb Mar Apr May Jun Jul Aug Sep Nov Oct Nov Dec') do (
>> 16. set result=%DAY% %%a %DD% %ztime% %YYYY%)
>> 17. if [%1] NEQ [] set result=%result% -- %*
>> 18. endlocal&echo %result%
>> =====end C:\cmd\util\xnow.cmd====================
>
>
> Phil, what about changing regional settings?
> On my W2K machine, Date/t gives me:
>
> N:\>date /t
> Fri 2002-08-16
>
> I prefer YMD as my date format using - instead of /.
>
> That's why I ended up using vbscript to get the date from the
> windows API - because is 01-02-03 January 2, 2003 (MDY)
> or February 3, 2001? (YMD)
>
> I guess if you hated vbscript you could use regedit to
> extract the regkey for the regional settings, but that's
> a lot of work.
>
> Ray
>

--

ray

unread,
Aug 16, 2002, 4:23:45 PM8/16/02
to
Phil Robyn wrote:
> ray wrote:
>
>> Phil Robyn wrote:
>>
>>> 11. for /f "tokens=1-4 delims=/ " %%a in ('date /t') do (
>>
>
> 11. for /f "tokens=1-4 delims=- " %%a in ('date /t') do (
>
>>> 12. set DAY=%%a&set MM=%%b& set DD=%%c& set YYYY=%%d)
>>
>
> 12. set DAY=%%a&set MM=%%c& set DD=%%d& set YYYY=%%b)
>
>>> 13. if %MM% LSS 10 set MM=%MM:~1%
>>> 14. for /f "tokens=%MM%" %%a in (
>>> 15. 'echo Jan Feb Mar Apr May Jun Jul Aug Sep Nov Oct Nov Dec') do (
>>> 16. set result=%DAY% %%a %DD% %ztime% %YYYY%)
>>> 17. if [%1] NEQ [] set result=%result% -- %*
>>> 18. endlocal&echo %result%
>>> =====end C:\cmd\util\xnow.cmd====================
>>


I guess what I meant was - I prefer the vbscript because that
way no matter who's logged on and whatever the region is
set to, it'll still work.

I've been nailed with this before - MS changed some error
messages from NT4 to Win2K and stuff breaks....

Ray

Phil Robyn

unread,
Aug 16, 2002, 6:49:25 PM8/16/02
to

Others have previously posted to this newsgroup a 'region-independent'
solution (batch file, no VB script); I'm just too lazy to dig it up.
:-)

Al Dunbar

unread,
Aug 16, 2002, 10:34:44 PM8/16/02
to

"rachel" <ldfkg...@sldfldsk.net> wrote in message
news:ulolrls...@corp.supernews.com...

> Yah I did leave that out. But I didn't give up and I found that choice.exe
> in the windows2000 resource kit, and spend several hours writing the
> following: http://junk.directivex.com/howto/moms-batch2.txt (it uses 3rd
> party tools: xxcopy, now, zip, and choice of course).
>
> What took most my time was figuring out that the "IF ERRORLEVEL..."
requires
> the last option listed 1st.

If you have the w2k reskit, are you using NT4 or w2k/xp? If w2k/xp, consider
this:

set answer=no
set/p answer=Do you want to copy to floppy (yes or no)?
if /i "%answer%" EQU "yes" (
copy commands...
) else (
echo.OK, then, I won't copy to floppy.
)

Clay Calvert

unread,
Aug 17, 2002, 7:51:18 AM8/17/02
to
On Thu, 15 Aug 2002 18:36:55 -0700, "rachel" <ldfkg...@sldfldsk.net>
wrote:

>Yah I did leave that out. But I didn't give up and I found that choice.exe

>in the windows2000 resource kit.

Here's an old trick that works in most MS operating systems. A
writeable %temp% directory is required.

@echo off
type nul>%temp%\~YesOrNo.tmp
echo Would you like to do this now [y/n]?
del /p %temp%\~YesOrNo.tmp>nul
if not exist %temp%\~YesOrNo.tmp goto Yes
Echo Selected "No"
del %temp%\~YesOrNo.tmp
goto end
:Yes
Echo Selected "Yes"
:end

Clay Calvert
CCal...@Wanguru.com
Replace "W" with "L"

0 new messages