Menu From the News
Page 6
Index
Index Page 5 | Page 7 | Nomenclature


     A fast number generator,
                Version no 1. -- Speed
                Version no 2. An all-round and fast num generator.
     Permutations and combinations
     Date. -- Legoland.bat
     Time. -- Pipe files/junk files in the TEMP environment.
     File contents comparison.
     File date comparison,
                Version no 1. 29 lines and 1356 bytes.
                Version no 2. 22 lines and 1106 bytes.







A fast number generator

My jumping-off point:

    @GOTO %2 !
    :!
    @ECHO off
    FOR %%! in (0 1 2 3 4 5 6 7 8 9) do CALL %0 %1 %2 %3 %4 %5 %6 %7 %8 %%!
    GOTO END
    :0
    :1
    :2
    :3
    :4   If the number 2, see line no 1, (@GOTO %2 !) is substituted with
    :5   number 3, (@GOTO %3 !), then you'll get 3 digits instead of 2...
    :6
    :7
    :8
    :9
    IF 0==%1 FOR %%c in (SHIFT GOTO:9 SET) do %%c Align_R= %Align_R%
    ECHO.%Align_R% %1%2%3%4%5%6%7%8%9
    SET Align_R=
    IF  23==%1%2%3%4%5%6%7%8%9 : EXIT
    :END

The <Usenet>.


Numb_GEN.bat; Copy and paste 151 lines in 3.209 bytes:


@GOTO %1 Program
:L__Aligned
    IF 0==%2 FOR %%c in (SHIFT GOTO:L__Aligned) do %%c
    GOTO C__Aligned
:R__Aligned
    IF 0==%2 FOR %%c in (SHIFT GOTO:R__Aligned SET) do %%c A= %A%
    GOTO C__Aligned
:40
FOR %%! in (0 1 2 3 4 5 6 7 8 9) do CALL %0 %G5% %2 %3 %4 %5 %%!
    GOTO EOF
:30
CALL %0 %G4%4%B5% %2 %3 %4 0
:31
CALL %0 %G4%4%B5% %2 %3 %4 1
:32
CALL %0 %G4%4%B5% %2 %3 %4 2
:33
CALL %0 %G4%4%B5% %2 %3 %4 3
:34
CALL %0 %G4%4%B5% %2 %3 %4 4
:35
CALL %0 %G4%4%B5% %2 %3 %4 5
:36
CALL %0 %G4%4%B5% %2 %3 %4 6
:37
CALL %0 %G4%4%B5% %2 %3 %4 7
:38
CALL %0 %G4%4%B5% %2 %3 %4 8
:39
CALL %0 %G4%4%B5% %2 %3 %4 9
    FOR %%c in (SET GOTO:EOF) do %%c B4=0
:20
CALL %0 %G3%3%B4% %2 %3 0
:21
CALL %0 %G3%3%B4% %2 %3 1
:22
CALL %0 %G3%3%B4% %2 %3 2
:23
CALL %0 %G3%3%B4% %2 %3 3
:24
CALL %0 %G3%3%B4% %2 %3 4
:25
CALL %0 %G3%3%B4% %2 %3 5
:26
CALL %0 %G3%3%B4% %2 %3 6
:27
CALL %0 %G3%3%B4% %2 %3 7
:28
CALL %0 %G3%3%B4% %2 %3 8
:29
CALL %0 %G3%3%B4% %2 %3 9
    FOR %%c in (SET GOTO:EOF) do %%c B3=0
:10
CALL %0 %G2%2%B3% %2 0
:11
CALL %0 %G2%2%B3% %2 1
:12
CALL %0 %G2%2%B3% %2 2
:13
CALL %0 %G2%2%B3% %2 3
:14
CALL %0 %G2%2%B3% %2 4
:15
CALL %0 %G2%2%B3% %2 5
:16
CALL %0 %G2%2%B3% %2 6
:17
CALL %0 %G2%2%B3% %2 7
:18
CALL %0 %G2%2%B3% %2 8
:19
CALL %0 %G2%2%B3% %2 9
    FOR %%c in (SET GOTO:EOF) do %%c B2=0
:00
CALL %0 %G1%1%B2% 0
:01
CALL %0 %G1%1%B2% 1
:02
CALL %0 %G1%1%B2% 2
:03
CALL %0 %G1%1%B2% 3
:04
CALL %0 %G1%1%B2% 4
:05
CALL %0 %G1%1%B2% 5
:06
CALL %0 %G1%1%B2% 6
:07
CALL %0 %G1%1%B2% 7
:08
CALL %0 %G1%1%B2% 8
:09
CALL %0 %G1%1%B2% 9
    FOR %%c in (SET GOTO:EOF) do %%c B1=0
:Program
@ECHO off
FOR %%v in (G1 G2 G3 G4 G5 B1 B2 B3 B4 B5) do SET %%v=
::  ----------- Config. Begin and End, (1...5 digits),
    SET B=9985
    SET E=10007

    ECHO..|CHOICE/c}%E%. Set n length of E >NUL
    FOR %%} in (1 2 3 4 5) do IF errorlevel 77%%} SET n=%%}

CALL %0 B 1 2 3 4 5 Set B1...Bn
FOR %%c in (SET GOTO) do %%c A=
:B
    ECHO..|CHOICE/c}%B%. Set B length as E >NUL
    IF NOT errorlevel 77%n% FOR %%c in (SET GOTO) do %%c B=0%B%
:n
    ECHO.%B%.|CHOICE/c.0123456789>NUL
    FOR %%} in (0 1 2 3 4 5 6 7 8 9) do IF errorlevel 77%%} SET A=%%}
    SET B%2=%A%
      IF %2==%n% FOR %%c in (GOTO:EOF SET) do %%c B=
    FOR %%%A% in (%%) do SET B=%%%B%
FOR %%c in (SHIFT GOTO:n) do %%c

:A
CHOICE/n/c1LKKKK2RM3C -- Alignment?, 1: Left, 2: Right or 3: Center --
FOR %%_ in (C R L) do IF NOT errorlevel 100%%_ SET G%n%=%%___Align
    IF NOT errorlevel 10 SET A=0
    IF NOT errorlevel 4 SET A= 0
    FOR %%v in (%B1% %B2% %B3% %B4% %B5%) do IF NOT %%v==0 SET A=
    GOTO 0%B1%
:Done
    FOR %%v in (B1 B2 B3 B4 B5 n G%n% E) do SET %%v=
    @:EXIT
:41
CALL %0 %G5% %2 %3 %4 %5 1
:42
CALL %0 %G5% %2 %3 %4 %5 2
:43
CALL %0 %G5% %2 %3 %4 %5 3
:44
CALL %0 %G5% %2 %3 %4 %5 4
:45
CALL %0 %G5% %2 %3 %4 %5 5
:46
CALL %0 %G5% %2 %3 %4 %5 6
:47
CALL %0 %G5% %2 %3 %4 %5 7
:48
CALL %0 %G5% %2 %3 %4 %5 8
:49
CALL %0 %G5% %2 %3 %4 %5 9
    FOR %%c in (SET GOTO:EOF) do %%c B5=0
:C__Aligned
    ECHO.%A% %2%3%4%5%6
    SET A=
    IF %E%'==%2%3%4%5%6' GOTO Done
:EOF


Speed testing were performed by using the below (and very simple) Times.bat.
I executed a DEFRAG of my RAM Drive, then I was running something like this:
    @ECHO off
    ECHO REF
    ECHO 0|TIME>NUL
    %COMSPEC%/cREF
    ECHO.|TIME|FIND "0">>%TEMP%.\REF.TMP
    ECHO MOD
    ECHO 0|TIME>NUL
    %COMSPEC%/cMOD
    ECHO.|TIME|FIND "0">>%TEMP%.\MOD.TMP
    %0 endless looping...
End of Times batch.

PS. If the modified batch; MOD.BAT (a copy of my reference batch; REF.BAT,
    then modified) was obvious faster than the REF.BAT file, then the file
    was deleted and the MOD.BAT file were renamed to REF.BAT, and so on...
    The last 15/100 seconds was squeezed by renaming the labels along with
    another sort order of the label names.

    It seems that DOS is reading the labels from the left to the right, so
    GOTO 99 slow,
    :98
    :99

    GOTO 99 fast,
    :89
    :99

    Since DOS would search any labels from the beginning of the file, then
    the most affected part should be at the end of the file without a GOTO
    (see the label named C__Aligned). The second most affected part should
    be in the beginning of the file, and so on... That was and is logical.

    @ECHO off
    %2
    ECHO %0
    CALL %0 GOTO:4'th SHIFT

    :the second most affected part
                          ECHO very often.
               GOTO END
    :the 3'th most affected part
                          ECHO Often
               GOTO END
    :4'th most affected part
                          ECHO.On rare occasions,
               GOTO END  (dot)^
    :the most affected part
                          ECHO Very very often
    :END


An all-round and fast num generator

  Notice: Some of the syntax constructed below is
  much faster than the similar syntax used in the
  previous version no 1.

  Generate the numbers from 12345678 to 12345687,

  :: Don't exceed 8 digits.
     @ECHO OFF
     %COMSPEC%/cNG_0_B_E.BAT 0 12345678 12345687
     ECHO Done

  Prefix of zero(s) in the configuration of the calling file is allowed.
  Both the below examples would count from 2 to 10,

     %COMSPEC% /c NG_0_B_E.BAT 0 002 00000010

     %COMSPEC% /c NG_0_B_E.BAT 0 00000002 010

  To generate all numbers 1... 99999999, just
  double click the batch file.

  84 lines in 2480 bytes,

@GOTO %1 0  Number Generator, NG_0_B_E.BAT
:7          Usage: %COMSPEC%/cNG_0_B_E 0 [Begin value] [End value]
FOR %%! in (%L% 9) do CALL %0 8 %2 %3 %4 %5 %6 %7 %8 %%!
GOTO EOF
:6
IF 9==%B% CALL %0 SUB %B7%
FOR %%! in (%L% 9) do CALL %0 %B%7 %2 %3 %4 %5 %6 %7 %%!
GOTO EOF
:5
IF 9==%B% CALL %0 SUB %B6%
FOR %%! in (%L% 9) do CALL %0 6 %2 %3 %4 %5 %6 %%!
GOTO EOF
:4
IF 9==%B% CALL %0 SUB %B5%
FOR %%! in (%L% 9) do CALL %0 5 %2 %3 %4 %5 %%!
GOTO EOF
:97
IF 9==%B% CALL %0 SUB %B8%
FOR %%! in (%L% 9) do CALL %0 8 %2 %3 %4 %5 %6 %7 %8 %%!
SET L=0 1 2 3 4 5 6 7 8
FOR %%c in (SET GOTO:EOF) do %%c B=
:3
IF 9==%B% CALL %0 SUB %B4%
FOR %%! in (%L% 9) do CALL %0 4 %2 %3 %4 %%!
GOTO EOF
:2
IF 9==%B% CALL %0 SUB %B3%
FOR %%! in (%L% 9) do CALL %0 3 %2 %3 %%!
GOTO EOF
:1
IF 9==%B% CALL %0 SUB %B2%
FOR %%! in (%L% 9) do CALL %0 2 %2 %%!
GOTO EOF
:SUB
IF 0==%2 SET L=0 1 2 3 4 5 6 7 8
IF 1==%2 SET L=1 2 3 4 5 6 7 8
IF 2==%2 SET L=2 3 4 5 6 7 8
IF 3==%2 SET L=3 4 5 6 7 8
IF 4==%2 SET L=4 5 6 7 8
IF 5==%2 SET L=5 6 7 8
IF 6==%2 SET L=6 7 8
IF 7==%2 SET L=7 8
IF 8==%2 SET L=8
IF 9==%2 SET L=
GOTO EOF
:0
@ECHO OFF
SET B=%2
SET E=%3
IF (%2)Begin == ()Begin SET B=1
IF (%3)End.. == ()End.. SET E=99999999
:: ---------------------------^^^^^^^^---- Eight or less digits.
FOR %%c in (0 00 000 0000 00000 000000 0000000) do IF 0%%c==%E% SET E=0
FOR %%c in (0 00 000 0000) do IF %%c==%B%     CALL %0 8 0 0 0 0 0 0 0 0 0
FOR %%c in (0 00 000 0000) do IF 0000%%c==%B% CALL %0 8 0 0 0 0 0 0 0 0 0
FOR %%i in (2 3 4 5 6 7 8) do SET B%%i=
ECHO..|CHOICE/c}%B%.>NUL
FOR %%} in (8 7 6 5 4 3 2) do IF NOT errorlevel 77%%} SET B%%}=0
SET B=%B8%%B7%%B6%%B5%%B4%%B3%%B2%%B%
SET E=%%%E%
CALL %0 N 1 2 3 4 5 6 7 8
ECHO.%E%.|CHOICE/c.0123456789>NUL
FOR %%c in (0 1 2 3 4 5 6 7 8 9) do IF ERRORLEVEL 77%%c SET B=%%c
FOR %%%B% in (%B%) do SET E=%E%
SET B=9
CALL %0 SUB %B1%
FOR %%! in (%L% %B%) do CALL %0 1 %%!
:!
FOR %%v in (B B1 B2 B3 B4 B5 B6 B7 B8 E L) do SET %%v=
FOR %%c in (CTTY GOTO) do %%c NUL
:N
ECHO.%B%.|CHOICE/c.0123456789>NUL
FOR %%} in (0 1 2 3 4 5 6 7 8 9) do IF errorlevel 77%%} SET L=%%}
SET  B%2=%L%
IF 8==%2 GOTO EOF
FOR %%%L% in (%%) do SET B=%%%B%
FOR %%0 in (%%) do SET E=%E%
FOR %%c in (SHIFT GOTO:N) do %%c
:8
FOR %%! in (%2000 %2%300 %2%3%40 %2%3%4%5) do IF 0000==%%! SHIFT
IF 0==%2 FOR %%! in (000 %300 %3%40 %3%4%5) do IF 000==%%! SHIFT
ECHO.%2%3%4%5%6%7%8%9
IF %E%==%2%3%4%5%6%7%8%9 GOTO !
:EOF


  Extra notes:
  Get rid of the zero(s). Two alternative solutions for the above Label 8,
  (two identical lines:)

    IF 0==%2 FOR %%! in (000 %300 %3%40 %3%4%5) do IF 000==%%! SHIFT
    IF 0==%2 FOR %%! in (000 %300 %3%40 %3%4%5) do IF 000==%%! SHIFT

  or as one line:

    IF 0==%2 FOR %%! in (0000000 %3000000 %3%400000 %3%4%50000 %3%4%5%6000 %
3%4%5%6%700 %3%4%5%6%7%80 %3%4%5%6%7%8%9) do IF 0000000==%%! SHIFT

  
  Prefixing the value of Begin with zero(s), so the length was eight digits.
  The following two examples is probably NOT faster than the used,

  Ex. 1: (the simple),

    ECHO..|CHOICE/c%B%.>NUL
    IF NOT errorlevel 9 SET B=0%B%
    IF NOT errorlevel 8 SET B=0%B%
    IF NOT errorlevel 7 SET B=0%B%
    IF NOT errorlevel 6 SET B=0%B%
    IF NOT errorlevel 5 SET B=0%B%
    IF NOT errorlevel 4 SET B=0%B%
    IF NOT errorlevel 3 SET B=0%B%
    IF NOT errorlevel 2 SET B=0%B%

  Ex. 2: (the more advanced),

    ECHO..|CHOICE/c%B%.>NUL
    IF NOT errorlevel 9 FOR %%! in (00000%%R%%P 0000%%R%%Q 000%%R%%R 00%%R%%
S 0%%R%%T %%R%%U %%¦) do IF errorlevel %%! SET B=%%!%B%
    FOR %%P in (0) do SET B=%B%
    FOR %%Q in (0) do SET B=%B%
    FOR %%R in (0) do SET B=%B%
    FOR %%S in (0) do SET B=%B%
    FOR %%T in (0) do SET B=%B%
    FOR %%U in (0) do SET B=%B%
    FOR %%¦ in (0) do SET B=%B%

  The used: (much better),

    ECHO..|CHOICE/c}%B%.>NUL
    FOR %%} in (8 7 6 5 4 3 2) do IF NOT errorlevel 77%%} SET B%%}=0
    SET B=%B8%%B7%%B6%%B5%%B4%%B3%%B2%%B%

  Notice the above Errorlevel 77 in "77%%}", can be substituted with an } as
  in "}%%}" but since some readers could find such a syntax a bit difficult,
  then I have used the number 77 instead of the }.

  It would be interesting to perform a speed test on Version no 1 with use
  of the improved syntax which I discovered when Version no 2 was developed.

  Here's another. The value of begin is 098 and the End value is 255:

@GOTO %1 Run
:Run
@ECHO off
SET G=SET
SET    I=0
GOTO %I%
:#
%G%    I=9
GOTO %I%
:##
%G%    I=8
GOTO %I%
:0
FOR %%! in (0 1 2 3 4 5 6 7 8 9) do CALL %0 #%1 %2 %3 %%!
GOTO G
:1
CALL %0 #%1 %2 %3 1
:2
CALL %0 #%1 %2 %3 2
:3
CALL %0 #%1 %2 %3 3
:4
CALL %0 #%1 %2 %3 4
:5
CALL %0 #%1 %2 %3 5
:6
CALL %0 #%1 %2 %3 6
:7
CALL %0 #%1 %2 %3 7
:8
CALL %0 #%1 %2 %3 8
:9
CALL %0 #%1 %2 %3 9
FOR %%c in (GOTO SET) do %%c G=GOTO:0
:###
ECHO %2%3%4
IF %2%3%4==255 FOR %%c in (CTTY GOTO) do %%c NUL
:G



Permutations and combinations

FOR loops can be used to make other things than numbers.

Since I found this topic interesting, then I have already
written different batch files on that topic but I won't
remove my older newbee versions spreadden around my Homepage.

Here's an example that shows all the 16 different ways that one
could write the word "CALL", (upper and lowercase).

@GOTO %9 %8 %7 %6 %5 %4%4 %3 %2 %1 !
:!
@ECHO off
CHOICE -- All Uppercase --
IF ERRORLEVEL 1 SET CASE=/
IF ERRORLEVEL 2 SET CASE=\
FOR %%! in (C c) do CALL %0 %1 %2 %3 %4 %5 %6 %7 %8 %%!
FOR %%c in (ECHO PAUSE CLS GOTO:END) do %%c.------Done!
:C
FOR %%! in (A a) do CALL %0 %1 %2 %3 %4 %5 %6 %7 %8 %%!
GOTO END
:A
:L
FOR %%! in (L l) do CALL %0 %1 %2 %3 %4 %5 %6 %7 %8 %%!
GOTO END
:LL
FOR %%! in (%CASE%%1%2%3%4%5%6%7%8%9) do ECHO%%!
:: CALL B-LEVELS.BAT %1%2%3%4%5%6%7%8%9
:: IF NOT ERRORLEVEL 18 FOR %%c in (ECHO PAUSE) do %%c.%1%2%3%4%5%6%7%8%9
:END


Date

@%1 ECHO OFF
   ECHO @PROMPT SET D0=$d>       %temp%.\$.BAT
   %COMSPEC%/c%temp%.\$.BAT|sort>%temp%.\$.BAT
   FOR %%c in (CAL DE) do %%cL   %temp%.\$.BAT

:: United Kingdom (UK) ; SET D0=Fri 15/03/2002
:: Denmark        (DK) ; SET D0=Fre 15-03-2002

%0 GOTO:0 %D0%
:0
  FOR %%c in (%3) do SET D3=%%c
  FOR %%c in (%3) do IF NOT %%c==%D3% SET D2=%%c
  IF (%D2%) == () Goto Hyphen
  FOR %%c in (%3) do IF NOT %%c==%D3% IF NOT %%c==%D2% SET D1=%%c
  FOR %%"/" in (" ") do SET D3=%%%D3%
  FOR %%"/" in (" ") do SET D2=%%%D2%
  FOR %%c in (%D3%) do SET D3=%%c
  FOR %%c in (%D2%) do SET D2=%%c
::GOTO:Result
  FOR %%c in (Object Count) do SET %%c=
  SET Rest=%%%D3%
  CALL %0 GOTO:N 3 3 3 3
          FOR %%c in (SET GOTO:Result) do %%c Rest=
:Hyphen
  FOR %%c in (Object Count) do SET %%c=
  SET Rest=%%%3
  CALL %0 GOTO:N 1 1 2 2 3 3 3 3
          FOR %%c in (SET GOTO:Result) do %%c Rest=
:N
  ECHO.%Rest%'|CHOICE/c'0123456789>NUL
  FOR %%c in (0 1 2 3 4 5 6 7 8 9) do IF errorlevel 77%%c SET Digit=%%c
  SET Object=%Object%%Digit%
  SET Count=/%Count%
  IF %Count%==// SET D%2=%Object%
  IF %Count%==// FOR %%c in (Object Count) do SET %%c=
  IF ()==(%3)    FOR %%c in (SET GOTO:EOF) do %%c Digit=
  FOR %%-       in (%%) do SET Rest=%Rest%
  FOR %%.       in (%%) do SET Rest=%Rest%
  FOR %%%Digit% in (%%) do SET Rest=%Rest%
  FOR %%c in (SHIFT GOTO:N) do %%c
:Result
  ECHO. %D0%
  ECHO.
  ECHO. Weekday: %2
  ECHO.    Date: %3
  ECHO.      D1: %D1%
  ECHO.      D2:    %D2%
  ECHO.      D3:         %D3%
  FOR %%c in (0 1 2 3) do SET D%%c=
:EOF


Legoland.bat

The following batch file is based on the above experiment.

A lot of users want to be able to write/rename a file with
the current DATE. Therefore, many DOS batch writers, tried
to construct such a solution but since another maybe using
a different format of the DATE, or using a CONFIG.SYS file
which is wrong/badly written (or missing), then they often
havn't succeeded a definitive solvable method.

@%1 ECHO OFF
   ECHO @PROMPT SET D0=$d>                %temp%.\$.BAT
   %COMSPEC% /c %temp%.\$.BAT | find "="> %temp%.\$.BAT
   FOR %%c in (CAL DE) do %%cL            %temp%.\$.BAT
%0 GOTO:0 %D0%
:0 REM if upside-down, set Errorlevel 0.> %temp%.\$.BAT
   FOR %%c in (.01.23-1993 .) do ECHO%%c>>%temp%.\$.BAT
   DATE > NUL                           < %temp%.\$.BAT
   ECHO.%3| DATE | find "1993" > NUL

GOTO Test skipped (Prefix double colon on this line to test all formats)
CHOICE/n/c12345 ˙Press a number, [1...5]:˙
IF NOT ERRORLEVEL 2 IF ERRORLEVEL 1% slash marks % SET D0=Sat 23/01/1993
IF NOT ERRORLEVEL 3 IF ERRORLEVEL 2% periods     % SET D0=Sat 23.01.1993
IF NOT ERRORLEVEL 4 IF ERRORLEVEL 3% hyphens     % SET D0=Sat 23-01-1993
IF NOT ERRORLEVEL 5 IF ERRORLEVEL 4% upside-down % SET D0=Sat 01-23-1993
IF NOT ERRORLEVEL 5 IF ERRORLEVEL 4                %COMSPEC%/cREM: zero.
IF NOT ERRORLEVEL 6 IF ERRORLEVEL 5% reversed    % SET D0=Sat 1993-01-23
%0 GOTO:Test %D0%
:Test skipped

   FOR %%c in (0 1 2 3 4) do SET D%%c=
   SET Rest=%%%3
   IF NOT ERRORLEVEL 1 CALL %0 GOTO:N 2 1 3 4 * upside-down
   IF /==%Rest%/               GOTO:Result (United States).
   ECHO.-.|CHOICE/C.%3>NUL
   IF ERRORLEVEL 6 IF NOT ERRORLEVEL 7 CALL %0 GOTO:N 3 4 2 1 * reversed
   IF /==%Rest%/ GOTO:Result (Canadian-French, Sweden, Poland, Hungary).
         CALL %0 GOTO:N 1 2 3 4 * hyphen, slash mark or period
                 GOTO:Result (Netherlands, Portugal, Denmark).
:N
   ECHO.%Rest%'|CHOICE /c'0123456789>NUL
   FOR %%c in (0 1 2 3 4 5 6 7 8 9) do IF errorlevel 77%%c SET DA=%%c
   FOR %%%DA% in (%%) do SET Rest=%Rest%
   ECHO.%Rest%'|CHOICE /c'0123456789>NUL
   FOR %%c in (0 1 2 3 4 5 6 7 8 9) do IF errorlevel 77%%c SET DB=%%c
   SET D%2=%DA%%DB%
   IF *==%3 FOR %%c in (SET GOTO:EOF) do %%c Rest=
   FOR %%%DB% in (%%) do SET Rest=%Rest%
   FOR %%"/"  in (%%) do SET Rest=%Rest%
   FOR %%-    in (%%) do SET Rest=%Rest%
   FOR %%.    in (%%) do SET Rest=%Rest%
   FOR %%c in (SHIFT GOTO:N) do %%c
:Result
   ECHO.    Date: %2 %3
   ECHO.
   ECHO.     Day: %D1%
   ECHO.   Month: %D2%
   ECHO. Century: %D3%
   ECHO.    Year: %D4%
   FOR %%c in (A B 1 2 3 4) do SET D%%c=
   DEL %temp%.\$.BAT
:EOF

5 different formats. The following table contains each country
including the country code along with the date and time format

Hyphen ---------------------------- Dd-Mm-CcYy ---------------
-
      Denmark                 045   23-01-1993   17.35.00
      Netherlands             031   23-01-1993   17:35:00
      Portugal                351   23-01-1993   17:35:00
      International. English  061   23-01-1993    5:35:00.00p
-
& reversed                   ------ CcYy-Mm-Dd ---------------

      Sweden                  046   1993-01-23   17.35.00
      Yugoslavia              038   1993-01-23   17:35:00
      Poland                  048   1993-01-23   17:35:00
      Canadian-French         002   1993-01-23   17:35:00
      Czechoslovakia          042   1993-01-23   17:35:00
      Hungary                 036   1993-01-23   17:35:00
-
& upside-down                ------ Mm-Dd-CcYy ---------------

      United States           001   01-23-1993    5:35:00.00p

Slash mark ------------------------ Dd/Mm/CcYy ---------------
/
      Italy                   039   23/01/1993   17.35.00
      Belgium                 032   23/01/1993   17:35:00
      Brazil                  055   23/01/1993   17:35:00
      Spain                   034   23/01/1993   17:35:00
      United Kingdom          044   23/01/1993   17:35:00.00
      Latin America           003   23/01/1993    5:35:00.00p

Period ---------------------------  Dd.Mm.CcYy ---------------
.
      Finland                 358   23.01.1993   17.35.00
      France                  033   23.01.1993   17:35:00
      Germany                 049   23.01.1993   17:35:00
      Norway                  047   23.01.1993   17:35:00
      Switzerland             041   23.01.1993   17,35,00
______________________________________________________________

  Links: DATE.BAT



Pipe file / junk file.

Pipe/junk files is usual found in the TEMP environment.

Such files is typically left behind in the C:\WINDOWS\TEMP folder
and was used temporary by an application, which has finished some
tasks and then forgot to delete that file(s). Windows is so dying
and your computer become slow as a turtle.

I often delete such files. Example: BHBDCFED (no file extension).

Split such a file name into pairs of letters: BH BD CF ED

Then convert each letter in the name as follows:
  A=0 B=1 C=2 D=3 E=4 F=5 G=6 H=7 I=8 J=9 K=a L=b M=c N=d O=e P=f

Producing: 17 13 25 43

Treat as four hexadecimal numbers, convert each of them
to decimal separately: 23 19 37 67

=time of PIPE file creation: 23hr 19min 37sec 0.67secs.

To difficult to figure out / impossible, so, I just wrote a batch
file, which like to do that converting/calculation instead of me.
I have named my batch as the number of possibilities, 8640000.BAT

Prof. Stockton, (Surrey, UK), have now informed me about that the
possibilities, should be 1573040. Since 55 ms corresponds to 18.2
Hz, which is obtained by 14.3 MHz /  12 /  65536, and the 14.3 is
4 times the NTSC colour subcarrier frequency, which is a fraction
of exactly 315 MHz. The DOS clock is therefore nominally in error
by 1.55 ppm or so - well within the probable crystal accuracy, of
course. Yes Yes, that was very interesting, jam for the Press but
they can't get me to rename my batch file :-),

  USAGE: Run the batch as is, and the junk file example: BHDLDLGD
         is used.

         The below batchfile also allows a single junk file to be
         dragged & dropped onto the icon of this batch,

(Remove the four comments about broken/wrapped lines along with unwrapping.)
  @ECHO OFF
  %2 IF ()==(%1) FOR %%C in (SET GOTO:_Start) do %%C pfi=BHDLDLGD
  DIR /b %1> %temp%.\$$.BAT
  %COMSPEC% /C%0 -     GOTO:_Prefix
  FOR %%C in (CALL DEL GOTO:_Start) do %%C %temp%.\$$.BAT
  ::
:_PREFIX
  ::                 ECHO @ECHO OFF>>%temp%.\$$.BAT
  PROMPT SET pfi=
  CTTY NUL
  %COMSPEC% /C%temp%.\$$.BAT | sort> %temp%.\$$.BAT
  GOTO EOF

:_Start
  CALL %0 - GOTO:_Hex hr min sec secs
  CALL %0 - GOTO:_Dec hr min sec secs %hr% %min% %sec% %secs% Aa Aa

  ECHO. %hr%hr %min%min %sec%sec .%secs%secs time of pipe file creation.
  FOR %%C in (pfi hr min sec secs c) do SET %%C=
  GOTO EOF
:_Hex
  ECHO %pfi%'|choice/C'''ABCDEFGHIJKLMNOP>NUL
goto delete this line and unwrap the below broken/wrapped line:-------------
  FOR %%C in (P O N M L K J I H G F E D C B A) do IF NOT ERRORLEVEL 50%%C SE
T C=%%C
  FOR %%%C% in (%%%Truncating 1'th character%) do SET pfi=%%%pfi%
  FOR %%C in (0 1 2 3 4 5 6 7 8 9) do IF errorlevel 26%%C SET C=%%C
goto delete this line and unwrap the below broken/wrapped line:-------------
  IF errorlevel 14 FOR %%C in (f e d c b a) do IF NOT errorlevel 99%%C SET C
=%%C
  ECHO %pfi%'|choice/C'''ABCDEFGHIJKLMNOP>NUL
  FOR %%C in (0 1 2 3 4 5 6 7 8 9) do IF errorlevel 26%%C SET %3=%C%%%C
goto delete this line and unwrap the below broken/wrapped line:-------------
  IF errorlevel 14 FOR %%C in (f e d c b a) do IF NOT errorlevel 99%%C SET %
3=%C%%%C
  IF %3== secs FOR %%C in (GOTO:EOF SET) do %%C C=
goto delete this line and unwrap the below broken/wrapped line:-------------
  FOR %%C in (P O N M L K J I H G F E D C B A) do IF NOT ERRORLEVEL 50%%C SE
T C=%%C
  FOR %%%C% in (%%%Truncating 1'th character%) do SET pfi=%pfi%
  FOR %%C in (SHIFT GOTO:_Hex) do %%C
:_Dec
  ECHO EXIT|%COMSPEC%/KPROMPT A$_MOVAX,4C%7$_INT21$_$_G$_|debug>NUL
  FOR %%C in (0 1 2 3 4 5 6 7 8 9 10) do IF ERRORLEVEL %%C0 SET C=%%C
  FOR %%C in (0 1 2 3 4 5 6 7 8 9) do IF ERRORLEVEL %C%%%C SET %3=%C%%%C
  IF NOT Aa==%8 FOR %%C in (SHIFT GOTO:_Dec) do %%C
:EOF

As a single tick corresponds to about 5.5 least significant digits, only
about 18% of plausible inputs ate legitimate.

Links:
Dr John Stockton.


File contents comparison.

The below is updated for WindowsXP, June 05, 2002.

For some time ago, I wrote a file named Equal.bat.
That file has been used a lot while it's placed on
my desktop. The purpose is that one could drag and
drop two files to see if they was identically.
Since it besides beeing a batch, also is an useful
tool for file contents comparison, I have now made
this new version. It should work in other language
than the English "FC: no differences encountered".

Ideas/Notes,

Note1: if you change the order of elements in this
       FOR loop, then you must use ">>", NOT: ">",

  FOR %%C in (echo goto:eof) do %%C SET first=%1>>%temp%.\COMP~TMP.BAT
  FOR %%C in (goto:eof echo) do %%C SET first=%1> %temp%.\COMP~TMP.BAT

Note2: if %1 should be blank, a file named as "goto:msg" is NOT found,

  IF NOT EXIST %1 goto:msg goto msg

Benny Pedersen,
PS. Win9X. (Unwrap line no 5),

BTW. You may upload or/and distribute this code/freeware as you wish
at your own Homepage, feed your dog with it or whatever. It is free!
but since I have updated this, then it would probably be a good idea
to include this link, URL: http://2dos.homepage.dk/batutil/NEWS6.HTM

  @echo off
  echo.
  if not ""=="%2" goto msg
  if not exist %1 goto:msg goto msg
  if exist %temp%.\COMP~TMP.BAT for %%c in (cal de goto:compares) do %%cL %t
emp%.\COMP~TMP.BAT
  for %%c in (goto:eof echo) do %%c set first=%1> %temp%.\COMP~TMP.BAT
  :compares
  for %%c in (%first% %1) do attrib.exe %%c
  echo.
  echo @prompt set FC: no d=">%temp%.\COMP~TMP.BAT
  fc.exe nul nul | find ":" >>%temp%.\COMP~TMP.BAT
  %comspec%/c%temp%.\COMP~TMP.BAT|find.exe "=""F">%temp%.\COMP~TMP.BAT
  for %%c in (cal de) do %%cl %temp%.\COMP~TMP.BAT
  fc.exe/a %first% %1/lb1
  fc.exe/b %first% %1|find %FC: no d%">nul
  set FC: no d=
  if errorlevel 2 set first=%1
  if %first%== %1 echo. Won't decide interim modifications.
  if %first%== %1 for %%c in (set goto:eof) do %%c first=
  if errorlevel 1 echo. Files is NOT
  echo. Identically.
  for %%c in (set goto:eof) do %%c first=
  :msg
  echo. To compare two files, drag & drop your first file on top
  echo. of this batch icon, then drag and drop your second file.
  :eof


File date comparison.

Rob Bisdom wrote

  Hallo,
 
  I want to compare two files with the same name but in a different
  location. The newest file by date should be copied to the location
  of the oldest file and overwrite the older one. I've looked for
  some time for the proper command but haven't found one.
  Maybe a combination of commands?
 
  Rob Bisdom

Hi,
I would first create two test files like this,

@echo off
if not exist C:\WORK\OLD" TEST"\nul xcopy nul C:\WORK\OLD" TEST"\>nul
if not exist C:\WORK\NEW" TEST"\nul xcopy nul C:\WORK\NEW" TEST"\>nul
echo This is old text.> C:\WORK\OLD" TEST\1 L0NG file name.test"
choice/T\,3/C\>NUL<AUX
echo This is new text.> C:\WORK\NEW" TEST\1 L0NG file name.test"
explorer C:\WORK\OLD" TEST"
explorer C:\WORK\NEW" TEST"
echo.
echo. The icon of the other batchfile
echo  is now ready to let you drag & drop those two test files.

Then I would test the below batch file.

  Benny Pedersen,
  PS. Tested in Win98,

@echo off
  if not ""=="%2"   FOR %%C in (ech got) do %%Co:-( To many inputs )-
  if not exist "%1" FOR %%C in (ech got) do %%Co:-( Blank/ no such )-
  if exist %temp%.\NUM1~TMP.BAT goto second
  for %%c in (goto:-( echo ) do %%c set first=%1>%temp%.\NUM1~TMP.BAT
  :second
  for %%c in (cal de) do %%cl %temp%.\NUM1~TMP.BAT
  if %first% == %1  for %%c in (ech got) do %%co:-( Got 2 of those )-
  if exist %temp%.\{TMP}\NUL for %%c in (ech got) do %%co:-( OOPS! )-
  XCOPY %first% %temp%.\{TMP}\ /Y > NUL
  XCOPY %1      %temp%.\{TMP}\ /Y > NUL
  FOR %%c in (C B A) do if not exist %temp%.\{TMP}\*.%%c set uniq=%%c
  CTTY NUL
  FOR %%c in (X Y) do REN %temp%.\{TMP}\*.* %%c.%uniq%
  if exist %temp%.\{TMP}\X.%uniq% echo:-( Names differ )->CON
  if exist %temp%.\{TMP}\X.%uniq% goto clean up
  deltree.exe /Y %temp%.\{TMP}\   > NUL
  COPY %first%   %temp%.\{TMP}\D1 > NUL
  COPY %1        %temp%.\{TMP}\D2 > NUL
  ECHO @PROMPT set newest=>   %temp%.\NUM1~TMP.BAT
  DIR %temp%.\{TMP} /B/OD>>   %temp%.\NUM1~TMP.BAT
  %COMSPEC%/C%temp%.\NUM1~TMP.BAT|find "=D">%temp%.\NUM1~TMP.BAT
  for %%c in (cal de) do %%cl %temp%.\NUM1~TMP.BAT
  IF D1==%newest% XCOPY %first% %1 /Y>NUL<%0
  IF D2==%newest% XCOPY %1 %first% /Y>NUL<%0
  :clean up
  for %%c in (first newest uniq) do set %%c=
  deltree.exe /Y %temp%.\{TMP} > NUL
  :-( eof ;-)

Todd Vargo, online the Usenet wrote something like this:

  xcopy %first% %temp%.\{TMP}\
  xcopy %1      %temp%.\{TMP}\ /d/y | find /v "0"
  if not errorlevel 1 echo Newest file is %first%> CON
  if     errorlevel 1 echo Newest file is %1     > CON

But since the above would fails when a zero exist in the filename,
then, I would prefere something like this:

  xcopy.exe<%0>nul %first% %1 /d/y
  xcopy.exe<%0>nul %1 %first% /d/y

Xcopy get its input from %0, i.e. the "f" in "@echo off".
An alternative is "ECHO f | XCOPY %first% %1 /d/y > NUL".

Now that we have found and reduced 2 lines instead of about 8, then I
would like to figure out, how to get rid of the folder named "{TMP}".
The section/part of the batch file, which use that folder is now only
the: "Names differ error-message-section". Maybe something like this:

  echo @prompt set noDiff=> %temp%.\NUM1~TMP.BAT
  fc.exe nul nul|find ":">> %temp%.\NUM1~TMP.BAT
  %comspec% /c%temp%.\NUM1~TMP.BAT|find.exe "=F">%temp%.\NUM1~TMP.BAT
  call             %temp%.\NUM1~TMP.BAT
  dir %first% /B/L>%temp%.\NUM1~TMP.BAT
  dir %1      /B/L>%temp%.\~X~.BIN
  fc.exe %temp%.\~X~.BIN %temp%.\NUM1~TMP.BAT|find.exe "%noDiff%">NUL
  if errorlevel 1 for %%c in (ech got) do %%co:-( Names differ )->CON
  if not errorlevel 1 echo The same filename from different locations

See U later (I'm going to eat some food)...

Benny,
PS.
Thanks Todd -- I will include a link to your posting on Usenet, later
at page 6, http://users.cybercity.dk/~bse26236/batutil/NEWS6.HTM#-Rob
Done: Use this link (mouse clicked), or this link (no mouse clicked).

:FileDATEcomp.bat (overwrite an old file with a new, see question.)
@echo off
  if not ""=="%2"   for %%e in (ech got) do %%eo:- [To many inputs]
  if not exist "%1" for %%e in (ech got) do %%eo:- [Blank/ No such]
  if exist %temp%.\NUM1~TMP.BAT goto second file
  for %%c in ( goto:-  echo ) do %%c.set f=%1> %temp%.\NUM1~TMP.BAT
:second file
  call     %temp%.\NUM1~TMP.BAT
  dir %1  /B/L>              %temp%.\NUM2~TMP.TMP
  if  %1==%f% for %%e in (ech got) do %%eo:-- [Two identical files]
  echo @prompt set noDiff=>                    %temp%.\NUM1~TMP.BAT
  fc.exe nul nul|find ":">>                    %temp%.\NUM1~TMP.BAT
  %comspec% /c%temp%.\NUM1~TMP.BAT |find "=F"> %temp%.\NUM1~TMP.BAT
  call                                         %temp%.\NUM1~TMP.BAT
  dir %f% /B/L>                                %temp%.\NUM1~TMP.BAT
  fc /b %temp%.\NUM1~TMP.BAT %temp%.\NUM2~TMP.TMP |find "%noDiff%">NUL
  if errorlevel 1   for %%e in (echo goto) do %%e -- [Names differ]
  xcopy<%0>nul %f% %1 /d/y
  xcopy<%0>nul %1 %f% /d/y
:-- clean up
  for %%f in (NUM1~TMP.BAT NUM2~TMP.TMP) do erase %temp%.\%%f > NUL
  for %%v in (f noDiff) do set %%v=
: - eof


-Top- Page 5 | Page 7 | Nomenclature