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

%time%...DOS vs. Win98

14 views
Skip to first unread message

Handi

unread,
Dec 6, 2001, 7:33:49 PM12/6/01
to
I can get the following batch to run quite well under windows and it renames
the specified file beautifuly ...but ...it won't do it in straight DOS.
Apparently the filename length or something prevents it. Whatever, it never
renames the file when run under straight DOS. Any way I can alter this
script so it will rename a file under DOS with some sort of current time?
The batch below was graciously provided to me several years ago by Todd
Vargo.

echo.|time|find "Current" >cu##ent.bat
echo set time=%%3> current.bat
call cu##ent.bat
echo = | choice /c=%time%= cu##ent.bat > current.bat
echo @echo off> cu##ent.bat
echo set time=>> cu##ent.bat
echo :LOOP>> cu##ent.bat
echo shift>> cu##ent.bat
echo if "%%1"=="]?" goto DONE>> cu##ent.bat
echo if "%%1"==":" goto COLON>> cu##ent.bat
echo goto NOTCOLON>> cu##ent.bat
echo :COLON>> cu##ent.bat
echo set time=%%time%%.>> cu##ent.bat
echo goto LOOP>> cu##ent.bat
echo :NOTCOLON>> cu##ent.bat
echo set time=%%time%%%%1>> cu##ent.bat
echo goto LOOP>> cu##ent.bat
echo :DONE>> cu##ent.bat
call current.bat
del cu??ent.bat > nul
ren g:\12345.ldq %time%.qyg


Todd Vargo

unread,
Dec 6, 2001, 10:05:28 PM12/6/01
to

"Handi" <handi...@spamnotcrosswinds.net> wrote in message
news:9up2pe$seo$1...@news.utelfla.com...

> I can get the following batch to run quite well under windows and it
renames
> the specified file beautifuly ...but ...it won't do it in straight DOS.
> Apparently the filename length or something prevents it. Whatever, it
never
> renames the file when run under straight DOS. Any way I can alter this
> script so it will rename a file under DOS with some sort of current time?
> The batch below was graciously provided to me several years ago by Todd
> Vargo.

<batch snipped>

In DOS, a filename is restricted to the 8.3 convention. It's not possible to
get the same format (hh.mm.ss.hhP.ext) the batch above provides while in the
Win9x GUI. BTW, the batch posted was done for my own study of parsing text
using CHOICE.COM as learned from this group. I no longer post batches using
this method due to the language/country restrictions of the Time/Date DOS
commands. Since I recall posting this batch, I'll make an exception.

The following revised batch should return the time (on your system) as
hhmmssmm in the 24 hour format. Note, the previous batch returned the time
in 12 hour PM format. HTH.

@echo off
echo @prompt Current time is $t $_ >current.bat
command /c current.bat > cu##ent.bat


echo set time=%%3> current.bat
call cu##ent.bat
echo = | choice /c=%time%= cu##ent.bat > current.bat
echo @echo off> cu##ent.bat
echo set time=>> cu##ent.bat
echo :LOOP>> cu##ent.bat
echo shift>> cu##ent.bat
echo if "%%1"=="]?" goto DONE>> cu##ent.bat

echo if "%%1"==":" goto LOOP>> cu##ent.bat
echo if "%%1"=="." goto LOOP>> cu##ent.bat


echo set time=%%time%%%%1>> cu##ent.bat
echo goto LOOP>> cu##ent.bat
echo :DONE>> cu##ent.bat
call current.bat
del cu??ent.bat > nul

ren 12345.ldq %time%.qyg


--
Todd Vargo (body of message must contain my name to reply by email)

Outsider

unread,
Dec 7, 2001, 2:11:02 AM12/7/01
to
Todd Vargo wrote:
>


> The following revised batch should return the time (on your system) as
> hhmmssmm in the 24 hour format. Note, the previous batch returned the time
> in 12 hour PM format. HTH.
>
> @echo off
> echo @prompt Current time is $t $_ >current.bat
> command /c current.bat > cu##ent.bat
> echo set time=%%3> current.bat
> call cu##ent.bat
> echo = | choice /c=%time%= cu##ent.bat > current.bat
> echo @echo off> cu##ent.bat
> echo set time=>> cu##ent.bat
> echo :LOOP>> cu##ent.bat
> echo shift>> cu##ent.bat
> echo if "%%1"=="]?" goto DONE>> cu##ent.bat
> echo if "%%1"==":" goto LOOP>> cu##ent.bat
> echo if "%%1"=="." goto LOOP>> cu##ent.bat
> echo set time=%%time%%%%1>> cu##ent.bat
> echo goto LOOP>> cu##ent.bat
> echo :DONE>> cu##ent.bat
> call current.bat
> del cu??ent.bat > nul
> ren 12345.ldq %time%.qyg
>

It got stuck at the choice line on my system.


X:\TEMP>COMMAND/Y/E:24000/Cgettime
gettime [Y/N]?Y
echo off [Y/N]?Y
echo @prompt Current time is $t $_ >current.bat [Y/N]?Y
command /c current.bat > cu##ent.bat [Y/N]?Y
echo set time=%3> current.bat [Y/N]?Y
call cu##ent.bat [Y/N]?Y
Current time is 8.01.54,97 [Y/N]?Y
set time=8.01.54 [Y/N]?Y
echo = | choice /c=8.01.54= cu##ent.bat > current.bat [Y/N]?Y


With ::@echo off


X:\TEMP>echo @prompt Current time is $t $_ >current.bat


X:\TEMP>command /c current.bat > cu##ent.bat


X:\TEMP>echo set time=%3> current.bat


X:\TEMP>call cu##ent.bat


X:\TEMP>

X:\TEMP>Current time is 8.06.35,48


X:\TEMP>set time=8.06.35


X:\TEMP>

X:\TEMP>echo = | choice /c=8.06.35= cu##ent.bat > current.bat


Why not just do this?

:: datetime.bat
@ECHO off
ECHO @PROMPT SET time=$t$_SET date=$d> %temp%.\dattim1.bat
%COMSPEC% /e:2048 /c %temp%.\dattim1.bat> %temp%.\dattim2.bat
CALL %temp%.\dattim2.bat
ECHO SET day=%%1>%temp%.\dattim2.bat
ECHO SET date=%%2>>%temp%.\dattim2.bat
CALL %temp%.\dattim2.bat %date%
DEL %temp%.\dattim?.bat
::

--
<!-Outsider//->
MS-DOS 6.22, Windows for Workgroups 3.11, Netscape Communicator 4.08

Walter Briscoe

unread,
Dec 7, 2001, 5:19:18 AM12/7/01
to
In article <3C106B86...@yahoo.com> of Fri, 7 Dec 2001 08:11:02 in
alt.msdos.batch, Outsider <nonvali...@yahoo.com> writes
[snip]

>Why not just do this?
>
>:: datetime.bat
>@ECHO off
>ECHO @PROMPT SET time=$t$_SET date=$d> %temp%.\dattim1.bat
>%COMSPEC% /e:2048 /c %temp%.\dattim1.bat> %temp%.\dattim2.bat
>CALL %temp%.\dattim2.bat
>ECHO SET day=%%1>%temp%.\dattim2.bat
>ECHO SET date=%%2>>%temp%.\dattim2.bat
>CALL %temp%.\dattim2.bat %date%
>DEL %temp%.\dattim?.bat
>::
>

I tried this in a W98 DOS box and it worked well.
However, it causes me to ask a supplementary question.
I have not seen it answered in the google archive.
What controls the date format?
The same format seems to be used for $d in the PROMPT command as is used
on output by the DATE command. I have just demonstrated the following:
D:\wfb> date
Current date is Fri 07/12/2001
Enter new date (dd-mm-yy):

D:\wfb>

On W9X, the format is independent of the date format set by the Regional
Settings Control Panel. I infer that both the formats of DATE and FORMAT
have regional variations (American usage would probably be something
like:
Current date is Fri 12/07/2001
Enter new date (mm-dd-yy):

D:\wfb>

There is some documentation of CONFIG.SYS elements in
%winbootdir%\CONFIG.TXT. I find the W98 version does not document the
country command which is a command which I have found affects the date
format. WME must use a different mechanism - I have not looked as I do
not have it to hand. The W95 version contains the following which also
applies to W98.

COUNTRY
========

Enables MS-DOS to use country-specific conventions for displaying times,
dates, and currency; for determining the order by which characters are
sorted; and for determining which characters can be used in filenames.
You
can use this command only in your Config.sys file.

The COUNTRY command configures MS-DOS to recognize the character set and
punctuation conventions observed when using one of the supported
languages.

Syntax

COUNTRY=xxx[,[yyy][,[drive:][path]filename]]

Parameters

xxx
Specifies the country code.

yyy
Specifies the character set for the country.

[drive:][path]filename
Specifies the location and name of the file containing country
information.

My example to select conventional British usage is
Country=044,850,C:\WINDOWS\COMMAND\country.sys
I selected American date formats with
Country=001,850,C:\WINDOWS\COMMAND\country.sys

Has anybody got a description of the format of country.sys to allow
hacking? e.g. I might want to use British formats except for date which
would be output as 2001-12-07 rather than 07/12/2001
--
Walter Briscoe

Outsider

unread,
Dec 7, 2001, 8:27:54 AM12/7/01
to
Walter Briscoe wrote:
>
> In article <3C106B86...@yahoo.com> of Fri, 7 Dec 2001 08:11:02 in
> alt.msdos.batch, Outsider <nonvali...@yahoo.com> writes
> [snip]
> >Why not just do this?
> >
> >:: datetime.bat
> >@ECHO off
> >ECHO @PROMPT SET time=$t$_SET date=$d> %temp%.\dattim1.bat
> >%COMSPEC% /e:2048 /c %temp%.\dattim1.bat> %temp%.\dattim2.bat
> >CALL %temp%.\dattim2.bat
> >ECHO SET day=%%1>%temp%.\dattim2.bat
> >ECHO SET date=%%2>>%temp%.\dattim2.bat
> >CALL %temp%.\dattim2.bat %date%
> >DEL %temp%.\dattim?.bat
> >::
> >
>
> I tried this in a W98 DOS box and it worked well.

Glad to hear it. I was wondering since there was no "$_" after "$d".
That sometimes cause problems in newer DOS versions, in or out of Windows.
One thing about that batch is, if it is a single digit hour there
is a leading space in the variable.

> However, it causes me to ask a supplementary question.
> I have not seen it answered in the google archive.
> What controls the date format?

Good question.

...snipped

> COUNTRY
> ========
...snipped

I don't know why MS calls it a command. I wouldn't call it a command
because it can't be run at the prompt.

http://users.cybercity.dk/~bse26236/batutil/help/NLSFUNCS.HTM
Nlsfunc.exe

http://users.cybercity.dk/~bse26236/batutil/help/MODESDCS.HTM
MODE (Set Device Code Pages)



> My example to select conventional British usage is
> Country=044,850,C:\WINDOWS\COMMAND\country.sys
> I selected American date formats with
> Country=001,850,C:\WINDOWS\COMMAND\country.sys

I don't know if this any use, but in DOS press [Ctrl+Alt]+[F1] to
make the hardwired US codepage active and [Ctrl+Alt]+[F2] to
return to the GB. Problem is it only affects the keyboard :(.
It continues to work in edit, so it might(?) be useful there.



> Has anybody got a description of the format of country.sys to allow
> hacking? e.g. I might want to use British formats except for date which
> would be output as 2001-12-07 rather than 07/12/2001

I think I have the source code for it around here if you're
interested (MS-DOS 6.0).

William Allen

unread,
Dec 7, 2001, 11:46:21 AM12/7/01
to
"Handi" wrote in message

> Any way I can alter this
> script so it will rename a file under DOS with some sort of current time?
...snip
> ren g:\12345.ldq %time%.qyg

The following script uses CHOICE to strip all non-numerics
from a string. So the time in, say format: 16:41:57.70 is
reduced to 16415770 which is a suitable string for a filename.

NOTE that the REN line is inactivated by ECHO.{demo!}
which you MUST remove to activate. Relocate the TEMP.BAT
workfile to your TEMP folder if you wish.

====Begin cut-and-paste (omit this line)
@ECHO OFF
IF (GOTO:)==(%1) %1%2 (Subroutine handler)
SET TIME=
ECHO.EXIT|%COMSPEC%/k PROMPT $t&|%COMSPEC%/c %0 GOTO: _TM>TEMP.BAT
FOR %%C IN (CALL DEL) DO %%C TEMP.BAT
ECHO.{demo!}REN g:\12345.ldq %TIME%.qyg
SET TIME=

GOTO EOF (=Subroutine code follows=)
:_TM
CHOICE /C&0123456789 /n>NUL
FOR %%N IN (0 1 2 3 4 5 6 7 8 9) DO IF ERRORLEVEL 77%%N SET V=%%N
IF ERRORLEVEL 2 SET TIME=%TIME%%V%
IF ERRORLEVEL 2 GOTO _TM
ECHO.SET TIME=%TIME%

:EOF (End-of-file)

====End cut-and-paste (omit this line)
To use the code above, cut-and-paste the text between the ==== lines
into a file with extension .BAT and base name of your choice. Lines
that don't begin with two spaces have wrapped in transmission.


--
(pp) William Allen


Dr John Stockton

unread,
Dec 7, 2001, 8:55:23 AM12/7/01
to
JRS: In article <9up2pe$seo$1...@news.utelfla.com>, seen in
news:alt.msdos.batch, Handi <handi...@spamnotcrosswinds.net> wrote at
Thu, 6 Dec 2001 19:33:49 :-

>I can get the following batch to run quite well under windows and it renames
>the specified file beautifuly ...but ...it won't do it in straight DOS.
>Apparently the filename length or something prevents it. Whatever, it never
>renames the file when run under straight DOS. Any way I can alter this
>script so it will rename a file under DOS with some sort of current time?

ISTM that there can be little point in using centiseconds.

The following will output the command you seem to need. Redirect to a
batch file, then call & delete that; or, in DOS, use MASSEXEC.

NOWMINUS f2 k- r | COLS 'ren * 'g:\12345.ldq * 1- '.*
-> ren g:\12345.ldq 13-04-22.*

Using f16 will give UNIX time, seconds from 1970; you can chop the first
2 of the 10 digits, or use Hex.

If seconds-of-day (00000..86399) is useful, it could be provided. Fx:
looks at code - will be provided; coded f1026, tested, ready to upload,
but I want to think about Random.

NOWMINUS, COLS, MASSEXEC via sig line 3.

--
© John Stockton, Surrey, UK. j...@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
Web <URL: http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms & links.
PAS EXE TXT ZIP via <URL: http://www.merlyn.demon.co.uk/programs/00index.htm>
My DOS <URL: http://www.merlyn.demon.co.uk/batfiles.htm> - also batprogs.htm.

Todd Vargo

unread,
Dec 7, 2001, 6:03:06 PM12/7/01
to

"Outsider" <nonvali...@yahoo.com> wrote in message
news:3C106B86...@yahoo.com...

> Todd Vargo wrote:
> >
>
>
> > The following revised batch should return the time (on your system) as
> > hhmmssmm in the 24 hour format. Note, the previous batch returned the

<snip>


> Why not just do this?
>
> :: datetime.bat
> @ECHO off
> ECHO @PROMPT SET time=$t$_SET date=$d> %temp%.\dattim1.bat
> %COMSPEC% /e:2048 /c %temp%.\dattim1.bat> %temp%.\dattim2.bat
> CALL %temp%.\dattim2.bat
> ECHO SET day=%%1>%temp%.\dattim2.bat
> ECHO SET date=%%2>>%temp%.\dattim2.bat
> CALL %temp%.\dattim2.bat %date%
> DEL %temp%.\dattim?.bat
> ::

Outsider,

I don't recall the original thread the batch was posted to, but IIRC, it
only specified needing the time to rename the file. The reason my revised
batch fails for you (we probably discussed this then too) is because of the
comma in the output on your system. This is why I specifically said, "(on
your system)" in my reply to the OP. In the snipped text I also said, "the
batch posted was done for my own study of parsing text using CHOICE.COM" and


"I no longer post batches using this method due to the language/country

restrictions...". Perhaps I should have use all caps or other modifiers.(?)

0 new messages