• Announcements

    • xper

      MSFN Sponsorship and AdBlockers!   07/10/2016

      Dear members, MSFN is made available via subscriptions, donations and advertising revenue. The use of ad-blocking software hurts the site. Please disable ad-blocking software or set an exception for MSFN. Alternatively, become a site sponsor and ads will be disabled automatically and by subscribing you get other sponsor benefits.
tomasz86

How to merge two text files?

238 posts in this topic

I have a fixed list of files, let's say:

1.dll

2.dll

3.dll

...

100. dll (all filenames are different, here it's just an example)

I would like to copy each of them only if the file exists. Is there any better way than doing it like this?

IF EXIST 1.dll COPY 1.dll <destination>

IF EXIST 2.dll COPY 2.dll <destination>

etc.

Edited by tomasz86
0

Share this post


Link to post
Share on other sites

I have a fixed list of files, let's say:

1.dll

2.dll

3.dll

...

100. dll (all filenames are different, here it's just an example)

I would like to copy each of them only if the file exists. Is there any better way than doing it like this?

IF EXIST 1.dll COPY 1.dll <destination>

IF EXIST 2.dll COPY 2.dll <destination>

etc.

Is the <destination> always the same?

Or can you use a "configuration file" (like a CSV)?

LIke:

1.dll ,"C:\Windows\Whatever\"
2.dll,"C:\Somewhere Else\"
....
<source file>,<target destnation>

You do a FOR loop:

@ECHO OFF
SETLOCAL ENABLEEXTENSIONS
FOR /F "tokens=1,2 delims=," %%A IN (Files_to_copy.csv) DO (
ECHO IF EXIST %%A COPY /B %%A %%B
)

jaclaz

0

Share this post


Link to post
Share on other sites

I have a fixed list of files, let's say:

1.dll

2.dll

3.dll

...

100. dll (all filenames are different, here it's just an example)

I would like to copy each of them only if the file exists. Is there any better way than doing it like this?

IF EXIST 1.dll COPY 1.dll <destination>

IF EXIST 2.dll COPY 2.dll <destination>

etc.

I'm intrigued as to what you feel needs improvement in the samples you've provided.

You cannot copy what doesn't exist!

0

Share this post


Link to post
Share on other sites

Yzöwl,

I have a list of files (hundreds of files), ex.


  • _DEFAULT.PI_
    0401.CS_
    0404.CS_
    0405.CS_
    0406.CS_
    0407.CS_
    0408.CS_
    040B.CS_
    040C.CS_
    040D.CS_
    040E.CS_
    0410.CS_
    0411.CS_
    0412.CS_
    0413.CS_
    0414.CS_
    0415.CS_
    0416.CS_
    0419.CS_
    041D.CS_
    041F.CS_
    0804.CS_
    0816.CS_
    0C0A.CS_
    12520437.CP_
    12520850.CP_
    1394.IN_
    1394BUS.SY_
    192.DN_
    2195.138.1.BLD
    3DGARRO.CU_
    3DGMOVE.CU_
    3DGNESW.CU_
    3DGNO.CU_
    3DGNS.CU_
    3DGNWSE.CU_
    3DGWE.CU_
    3DSMOVE.CU_
    3DSNS.CU_
    3DSNWSE.CU_
    3DWARRO.CU_
    3DWMOVE.CU_
    3DWNESW.CU_
    3DWNO.CU_
    3DWNS.CU_
    3DWNWSE.CU_
    3DWWE.CU_
    8514FIX.FO_
    8514FIXE.FO_
    8514FIXG.FO_
    8514FIXR.FO_
    8514FIXT.FO_
    8514OEM.FO_
    8514OEME.FO_
    8514OEMG.FO_
    8514OEMR.FO_
    8514OEMT.FO_
    8514SYS.FO_
    8514SYSE.FO_
    8514SYSG.FO_
    8514SYSR.FO_
    8514SYST.FO_
    85775.FO_
    85855.FO_
    85F1257.FO_
    85S1257.FO_
    AAAAMON.DL_
    ABP480N5.SY_
    ACC_DIS.CH_
    ACCESS.CH_

Changing everything manually to

IF EXIST _DEFAULT.PI_ COPY _DEFAULT.PI_ <destination>
IF EXIST 0401.CS_ COPY 0401.CS_ <destination>

takes too much time. If I do just

COPY _DEFAULT.PI_ <destination>
COPY 0401.CS_ <destination>

then there is a "file not found" error on the screen (when the file doesn't exist) and the script is also much slower as it tries to copy all these files one by one.

Edited by tomasz86
0

Share this post


Link to post
Share on other sites

Changing everything manually to

The WHOLE idea about batch files is that you DO NOT change hundreds of lines manually!

That's ALSO exactly the ide of having a "configuration file".

You have same command line (which you change just once) and a LIST of files (source/destination) that it's much easier to create or change.

then there is a "file not found" error on the screen (when the file doesn't exist) ....

Meet REDIRECTION of standard output and standard error ;):

http://www.robvanderwoude.com/redirection.php

Also, please, ALWAYS use COPY /B when copying files, you never know:

http://ss64.com/nt/copy.html

This:

@ECHO OFF
SETLOCAL ENABLEEXTENSIONS
SET DESTINATION=C:\somewhere\
ECHO.>newfile.cmd
FOR /F "tokens=* delims=" %%A IN (list_of_dlls.txt) DO (
ECHO IF EXIST %%A COPY /B %%A %DESTINATION%>>newfile.cmd
)

Will create a new file "newfile.cmd" with all the entries in your list of dll's "list_of_dlls.txt" automatically (as opposed to manually)

jaclaz

Edited by jaclaz
0

Share this post


Link to post
Share on other sites

It works. Thank you :thumbup

I'll use COPY /B from now... is there something similar with MOVE?

0

Share this post


Link to post
Share on other sites

Using COPY /B serves no purpose when used in that manner, in fact it is the default mode when copying single files.

0

Share this post


Link to post
Share on other sites

Are you saying that pre-XP the resulting file copied, C:\MyFiles\Binary.ext, as a result of the following doesn't work or is somehow broken?

IF NOT EXIST C:\MYFILES\ MD C:\MYFILES
COPY A:\BINARY.EXT C:\MYFILES

0

Share this post


Link to post
Share on other sites

Are you saying that pre-XP the resulting file copied, C:\MyFiles\Binary.ext, as a result of the following doesn't work or is somehow broken?

IF NOT EXIST C:\MYFILES\ MD C:\MYFILES

NO, I am not.

I am saying what I said (and nothing else) ;).

I have always used /B (probably uneededly :blushing: ) because of the referenced page AND along the lines of "better be safe than sorry" philosophy.

Since it is common that the good MS guys almost silently change some little things in commands and their syntax, [b]if[/b] the behaviour in earlier version was different [b]then[/b] everything would make sense, or if you prefer I was trying to find an explanation why the SS64 site (normally very exact) carried some wrong info.

jaclaz

0

Share this post


Link to post
Share on other sites

@ECHO OFF
SETLOCAL ENABLEEXTENSIONS
SET DESTINATION=C:\somewhere\
ECHO.>newfile.cmd
FOR /F "tokens=* delims=" %%A IN (list_of_dlls.txt) DO (
ECHO IF EXIST %%A COPY /B %%A %DESTINATION%>>newfile.cmd
)

In the end I used this method as a basis:


SETLOCAL ENABLEEXTENSIONS
SET A=
SET B=
SET C=
FOR /F %%I IN ('DIR/A-D/B %A%') DO (
IF EXIST %B%\%%I (
COPY/B %B%\%%I %C%\
)
)

I also have another question related to this script. Is it possible to copy only specific files like "*.*_"? I tried adding


IF "%%~xI"==".*_"

but it doesn't work. It works only if the extension is specified, ex.


IF "%%~xI"==".dl_"

Nevermind, I got it work by changing

('DIR/A-D/B %A%')

to

('DIR/A-D/B %A%\*.*_')

Everything is fine but copying is very slow compared to just doing xcopy :}

Edited by tomasz86
0

Share this post


Link to post
Share on other sites

It really depends upon the full intent of your script. You may be able to simply change the For command Dir output.

You need to be aware that asking for small changes throughout the Topic can completely ruin the final result. If you actually provide a full and complete explanation of the batch file requirements from the outset it is likely that the solution will better suit your intent.

As a side note, a file extension with an underscore suffix does not necessarily mean that the file is compressed.

0

Share this post


Link to post
Share on other sites

Everything is fine but copying is very slow compared to just doing xcopy :}

A new approach :w00t::

  1. copy *everything* with XCOPY fast
  2. delete what you DO NOT need :whistle:

jaclaz

0

Share this post


Link to post
Share on other sites

Yzöwl,

the script is connected with the other one for merging Win2k's updates ("merging text files..." topic). It's supposed to update files from Service Pack 4 with newer versions that come from the merged updates.

I already prepared it and it's working so I don't really need more help in this topic ;) I used strings like this one and that's why I asked for help.

	FOR /F %%I IN ('DIR/A-D/B SPMER\i386\*.*_') DO (
EXPAND -R SPMER\i386\%%I TEMP\ >NUL
FOR /F %%I IN ('DIR/A-D/B TEMP') DO (
ECHO Checking i386\%%I
IF EXIST HFMER\%%I (
ECHO Processing i386\%%I&ECHO.
XCOPY/DY HFMER\%%I TEMP\ >NUL&DEL/Q HFMER\%%I >NUL
MAKECAB /D CompressionMemory=21 /D CompressionType=LZX TEMP\%%I /L SPMER\i386 >NUL
)
DEL/Q/S TEMP\%%I >NUL
)
)

I have also rewritten everything in the other script for merging updates so now it's simpler and doesn't use any other (HFSLIP etc.) sources except for the parts where jaclaz's scripts are used. I'll post an updated version in the other topic after I combine both together as now they are two separate scripts.

0

Share this post


Link to post
Share on other sites

Yzöwl,

the script is connected with the other one for merging Win2k's updates ("merging text files..." topic).

Okay, topics Merged.

0

Share this post


Link to post
Share on other sites

I want to edit lines in the original update.inf from w2k sp4 (after processing it by jaclaz's script to remove unnecessary spaces).

Is there any better (but still simple) way than this one?

SETLOCAL ENABLEDELAYEDEXPANSION


@ECHO OFF > update.txt
FOR /F "tokens=* delims= " %%I IN (update.inf) DO (
IF "%%I"=="CatalogFile = sp4.cat" (
ECHO ThisServicePackBuild = 1 >> update.txt
) ELSE (
ECHO %%I >> update.txt
)
)

@ECHO OFF > update2.txt
FOR /F "tokens=* delims= " %%I IN (update.txt) DO (
IF "%%I"=="MaxNtServicePackVersion = 1024 " (
ECHO MaxNtServicePackVersion = 1536 >> update2.txt
) ELSE (
ECHO %%I >> update2.txt
)
)

@ECHO OFF > update3.txt
FOR /F "tokens=* delims= " %%I in (update2.txt) do (
IF "%%I"=="ThisServicePackVersion = 1024 " (
ECHO ThisServicePackVersion = 1536 >> update3.txt
) ELSE (
ECHO %%I >> update3.txt
)
)

The problem is that one space at the end of each line is added in each newer file so it goes like this:

IF "%%I"=="CatalogFile = sp4.cat" <- no space
IF "%%I"=="MaxNtServicePackVersion = 1024 "<- 1 space
IF "%%I"=="ThisServicePackVersion = 1024 " <- 2 spaces
...

The other issue is that the script doesn't work if the output files are '.inf' files instead of '.txt' files. Why is this so?

Edited by tomasz86
0

Share this post


Link to post
Share on other sites

The space problem is being caused because you're making things too "neat" and "human readable". You have a space before ">> update.txt", so it adds a space. Batch is usually very literal when it comes to using redirection and comparison testing. You don't need any spaces before or after the ">>" or ">", unless you are trying to add them on purpose. In your case, I think if you change your code to:


SETLOCAL ENABLEDELAYEDEXPANSION

@ECHO OFF>update.txt
FOR /F "tokens=* delims= " %%I IN (update.inf) DO (
IF "%%I"=="CatalogFile = sp4.cat" (
ECHO ThisServicePackBuild = 1>>update.txt
) ELSE (
ECHO %%I>>update.txt
)
)

@ECHO OFF>update2.txt
FOR /F "tokens=* delims= " %%I IN (update.txt) DO (
IF "%%I"=="MaxNtServicePackVersion = 1024" (
ECHO MaxNtServicePackVersion = 1536>>update2.txt
) ELSE (
ECHO %%I>>update2.txt
)
)

@ECHO OFF>update3.txt
FOR /F "tokens=* delims= " %%I in (update2.txt) do (
IF "%%I"=="ThisServicePackVersion = 1024" (
ECHO ThisServicePackVersion = 1536>>update3.txt
) ELSE (
ECHO %%I>>update3.txt
)
)

that should take care of your spacing problem.

Cheers and Regards

0

Share this post


Link to post
Share on other sites

I see a potential problem with the example supplied by bphlpt above:

		ECHO ThisServicePackBuild = 1>> update.txt

The problem is that we generally use lazy redirection, when we write to stdout. ( >output.ext should be written as 1>output.ext )

This means that I'd expect stdout to not receive the value of ThisServicePackBuild.

0

Share this post


Link to post
Share on other sites

As always Yzöwl is right, if you have no space between the 1 and the > you will redirect standard output to file.

You can always leave the spaces and post-process with gsar changing [sPACE][CR][LF] to [CR][LF] .... :unsure:

Or see if redirection BEFORE line works, see point #(3) here:

http://www.robvanderwoude.com/redirection.php

jaclaz

0

Share this post


Link to post
Share on other sites

(ECHO ThisServicePackBuild = 1)>> update.txt

or

(ECHO ThisServicePackBuild = 1)1>> update.txt

will work.

0

Share this post


Link to post
Share on other sites

Or see if redirection BEFORE line works

It works :) Thank you.

The full script itself got pretty long but here are main parts of it:

1. Unpacking files to HFMER folder.


IF EXIST HF\*.EXE (
IF EXIST HFMER RD/Q/S HFMER
IF EXIST TEMP RD/Q/S TEMP
MD HFMER TEMP
FOR /F %%I IN ('DIR/A-D/B HF') DO (
ECHO.&ECHO Unpacking %%I
MD TEMP\HFMER&START/WAIT HF\%%I /Q /X:TEMP\HFMER
ECHO.
XCOPY/DEHRY TEMP\HFMER HFMER
ECHO.
IF EXIST TEMP\HFMER\UPDATE\update.inf COPY/B TEMP\HFMER\UPDATE\update.inf TEMP\%%I.inf >NUL
IF EXIST TEMP\HFMER\UPDATE\update_w2k.inf COPY/B TEMP\HFMER\UPDATE\update_w2k.inf TEMP\%%I.inf >NUL
IF EXIST TEMP\HFMER\UPDATE\update_win2k.inf COPY/B TEMP\HFMER\UPDATE\update_win2k.inf TEMP\%%I.inf >NUL
IF EXIST TEMP\HFMER\UPDATE\update.ver COPY/B TEMP\HFMER\UPDATE\update.ver TEMP\%%I.ver >NUL
RD/Q/S TEMP\HFMER >NUL
)

2. Merging update.ver


:: merging update.ver
CLS
ECHO.&ECHO Merging update.ver...&ECHO.
FOR /F %%A IN ('DIR/B TEMP\*.ver') DO (
FOR /F "skip=1 tokens=*" %%B IN (TEMP\%%A) DO (
ECHO TEMP\%%A -- %%B
ECHO %%B >>TEMP\update.txt
)
)
ECHO [SourceFileInfo] >TEMP\update.ver
SORT TEMP\update.txt >>TEMP\update.ver
:: removing duplicates in update.ver
TOOLS\yanklines.vbs TEMP\update.ver HFMER\UPDATE\update.ver >NUL

I had to modify yanklines in order to prevent new cmd.exe windows from popping up. I modified this line

scriptCommand = "cmd.exe /k "

to

scriptCommand = "cmd.exe /c "

The window still pops up but gets closed instantly.

3. Merging update.inf by jaclaz's script & yanklines


CLS
ECHO.&ECHO Merging update.inf...&ECHO.
COPY/B TOOLS\jaclaz\*.* >NUL
COPY/B HFMER\update\update.inf update.inf >NUL
splitinf.cmd update.inf >NUL
:: yanklines SPLIT_update\*.inf
XCOPY/EI SPLIT_update TEMP\SPLIT_update >NUL
IF EXIST TEMP\SPLIT_update\[1ndex]update.inf DEL/Q TEMP\SPLIT_update\[1ndex]update.inf >NUL
IF EXIST TEMP\SPLIT_update\*Add.Reg*]update.inf DEL/Q TEMP\SPLIT_update\*Add.Reg*]update.inf >NUL
IF EXIST TEMP\SPLIT_update\*AddReg*]update.inf DEL/Q TEMP\SPLIT_update\*AddReg*]update.inf >NUL
IF EXIST TEMP\SPLIT_update\[Strings]update.inf DEL/Q TEMP\SPLIT_update\[Strings]update.inf >NUL
FOR /F %%I IN ('DIR/B TEMP\SPLIT_update') DO (
START/WAIT TOOLS\yanklines.vbs TEMP\SPLIT_update\%%I SPLIT_UPDATE\%%I >NUL
)
join_dedupe_inf.cmd SPLIT_update.inf >NUL
beautify.cmd JOINED_update.inf >NUL
MOVE/Y BEAUTY_JOINED_update.inf HFMER\update\update.inf >NUL

DEL/Q update.inf splitinf.cmd join_dedupe_inf.cmd beautify.cmd fedit.exe gsar.exe split_update.inf joined_update.inf >NUL
RD/Q/S SPLIT_update >NUL
RD/Q/S TEMP >NUL

I know it's not ideal and many bypasses are used to make it work... but it does the job. Actually I've just noticed that deleting the *.inf files (look above) is not necessary anymore. They are related to CMSORT which I replaced with yanklines which is better and simpler, and what's the most important - it doesn't sort which is crucial in case of *Add*Reg* sections.

4. SP part - it's not finished yet and pretty long


:SP
IF EXIST HFMER\i386 RD/Q/S HFMER\i386 >NUL
IF EXIST TEMP RD/Q/S TEMP >NUL
MD TEMP

:: preparing HFMER
DEL/Q HFMER\empty.cat HFMER\iecustom.dll HFMER\spmsg.dll HFMER\spuninst.exe HFMER\updcustom.dll >NUL

IF EXIST HFMER\XPSP2_BINARYDROP (
COPY/B/Y HFMER\XPSP2_BINARYDROP\*.* HFMER\ >NUL
RD/Q/S HFMER\XPSP2_BINARYDROP >NUL
)

:: unpacking SP archive
CLS
ECHO.&ECHO Unpacking Service Pack files...&ECHO.
FOR /F %%I IN ('DIR/A-D/B SP') DO (
START/WAIT SP\%%I /Q /X:HFMER\
)

:: preparing SP files and removing duplicates

:: moving files from i386\i* to i386
MD HFMER\i386\iads HFMER\i386\iadsw HFMER\i386\iadw HFMER\i386\iapsw HFMER\i386\iasw HFMER\i386\iaw HFMER\i386\ips
MOVE HFMER\i386\ia\basicwk.in_ HFMER\i386\&DEL/Q HFMER\i386\id\basicwk.in_ HFMER\i386\ip\basicwk.in_ HFMER\i386\is\basicwk.in_ HFMER\i386\iw\basicwk.in_
MOVE HFMER\i386\ia\dcup5.in_ HFMER\i386\&DEL/Q HFMER\i386\id\dcup5.in_ HFMER\i386\ip\dcup5.in_ HFMER\i386\is\dcup5.in_ HFMER\i386\iw\dcup5.in_
MOVE HFMER\i386\ia\defltdc.in_ HFMER\i386\&DEL/Q HFMER\i386\id\defltdc.in_ HFMER\i386\ip\defltdc.in_ HFMER\i386\is\defltdc.in_ HFMER\i386\iw\defltdc.in_
MOVE HFMER\i386\ia\defltwk.in_ HFMER\i386\&DEL/Q HFMER\i386\id\defltwk.in_ HFMER\i386\ip\defltwk.in_ HFMER\i386\is\defltwk.in_ HFMER\i386\iw\defltwk.in_
MOVE HFMER\i386\ia\dmreg.inf HFMER\i386\&DEL/Q HFMER\i386\id\dmreg.inf HFMER\i386\ip\dmreg.inf HFMER\i386\is\dmreg.inf HFMER\i386\iw\dmreg.inf
MOVE HFMER\i386\ia\dwup.in_ HFMER\i386\&DEL/Q HFMER\i386\id\dwup.in_ HFMER\i386\ip\dwup.in_ HFMER\i386\is\dwup.in_ HFMER\i386\iw\dwup.in_
MOVE HFMER\i386\ia\fp40ext.in_ HFMER\i386\&DEL/Q HFMER\i386\id\fp40ext.in_ HFMER\i386\ip\fp40ext.in_ HFMER\i386\is\fp40ext.in_ HFMER\i386\iw\fp40ext.in_
MOVE HFMER\i386\ia\hivecls.inf HFMER\i386\&DEL/Q HFMER\i386\id\hivecls.inf HFMER\i386\ip\hivecls.inf HFMER\i386\is\hivecls.inf HFMER\i386\iw\hivecls.inf
MOVE HFMER\i386\ia\mchgr.in_ HFMER\i386\&DEL/Q HFMER\i386\id\mchgr.in_ HFMER\i386\ip\mchgr.in_ HFMER\i386\is\mchgr.in_ HFMER\i386\iw\mchgr.in_
MOVE HFMER\i386\ia\sceregvl.in_ HFMER\i386\&DEL/Q HFMER\i386\id\sceregvl.in_ HFMER\i386\ip\sceregvl.in_ HFMER\i386\is\sceregvl.in_ HFMER\i386\iw\sceregvl.in_
MOVE HFMER\i386\ia\tape.in_ HFMER\i386\&DEL/Q HFMER\i386\id\tape.in_ HFMER\i386\ip\tape.in_ HFMER\i386\is\tape.in_ HFMER\i386\iw\tape.in_
MOVE HFMER\i386\ia\usb.in_ HFMER\i386\&DEL/Q HFMER\i386\id\usb.in_ HFMER\i386\ip\usb.in_ HFMER\i386\is\usb.in_ HFMER\i386\iw\usb.in_
:: iads
MOVE HFMER\i386\ia\apcompat.in_ HFMER\i386\iads\&DEL/Q HFMER\i386\id\apcompat.in_ HFMER\i386\is\apcompat.in_
:: iadsw
MOVE HFMER\i386\ia\comntsrv.in_ HFMER\i386\iadsw\&DEL/Q HFMER\i386\id\comntsrv.in_ HFMER\i386\is\comntsrv.in_ HFMER\i386\iw\comntsrv.in_
MOVE HFMER\i386\ia\hiveusd.inf HFMER\i386\iadsw\&DEL/Q HFMER\i386\id\hiveusd.inf HFMER\i386\is\hiveusd.inf HFMER\i386\iw\hiveusd.inf
MOVE HFMER\i386\ia\iisdbg.in_ HFMER\i386\iadsw\&DEL/Q HFMER\i386\id\iisdbg.in_ HFMER\i386\is\iisdbg.in_ HFMER\i386\iw\iisdbg.in_
MOVE HFMER\i386\ia\machine.in_ HFMER\i386\iadsw\&DEL/Q HFMER\i386\id\machine.in_ HFMER\i386\is\machine.in_ HFMER\i386\iw\machine.in_
MOVE HFMER\i386\ia\netnwcli.in_ HFMER\i386\iadsw\&DEL/Q HFMER\i386\id\netnwcli.in_ HFMER\i386\is\netnwcli.in_ HFMER\i386\iw\netnwcli.in_
MOVE HFMER\i386\ia\netoc.in_ HFMER\i386\iadsw\&DEL/Q HFMER\i386\id\netoc.in_ HFMER\i386\is\netoc.in_ HFMER\i386\iw\netoc.in_
MOVE HFMER\i386\ia\netrass.in_ HFMER\i386\iadsw\&DEL/Q HFMER\i386\id\netrass.in_ HFMER\i386\is\netrass.in_ HFMER\i386\iw\netrass.in_
MOVE HFMER\i386\ia\netsnmp.in_ HFMER\i386\iadsw\&DEL/Q HFMER\i386\id\netsnmp.in_ HFMER\i386\is\netsnmp.in_ HFMER\i386\iw\netsnmp.in_
MOVE HFMER\i386\ia\netwlbsm.in_ HFMER\i386\iadsw\&DEL/Q HFMER\i386\id\netwlbsm.in_ HFMER\i386\is\netwlbsm.in_ HFMER\i386\iw\netwlbsm.in_
MOVE HFMER\i386\ia\ntfrsres.dl_ HFMER\i386\iadsw\&DEL/Q HFMER\i386\id\ntfrsres.dl_ HFMER\i386\is\ntfrsres.dl_ HFMER\i386\iw\ntfrsres.dl_
MOVE HFMER\i386\ia\setpwd.ex_ HFMER\i386\iadsw\&DEL/Q HFMER\i386\id\setpwd.ex_ HFMER\i386\is\setpwd.ex_ HFMER\i386\iw\setpwd.ex_
MOVE HFMER\i386\ia\wlbs.ch_ HFMER\i386\iadsw\&DEL/Q HFMER\i386\id\wlbs.ch_ HFMER\i386\is\wlbs.ch_ HFMER\i386\iw\wlbs.ch_
MOVE HFMER\i386\ia\wlbs.ex_ HFMER\i386\iadsw\&DEL/Q HFMER\i386\id\wlbs.ex_ HFMER\i386\is\wlbs.ex_ HFMER\i386\iw\wlbs.ex_
MOVE HFMER\i386\ia\wlbs.hl_ HFMER\i386\iadsw\&DEL/Q HFMER\i386\id\wlbs.hl_ HFMER\i386\is\wlbs.hl_ HFMER\i386\iw\wlbs.hl_
MOVE HFMER\i386\ia\wlbs.sy_ HFMER\i386\iadsw\&DEL/Q HFMER\i386\id\wlbs.sy_ HFMER\i386\is\wlbs.sy_ HFMER\i386\iw\wlbs.sy_
MOVE HFMER\i386\ia\wlbsctrl.dl_ HFMER\i386\iadsw\&DEL/Q HFMER\i386\id\wlbsctrl.dl_ HFMER\i386\is\wlbsctrl.dl_ HFMER\i386\iw\wlbsctrl.dl_
MOVE HFMER\i386\ia\wlbsprov.dl_ HFMER\i386\iadsw\&DEL/Q HFMER\i386\id\wlbsprov.dl_ HFMER\i386\is\wlbsprov.dl_ HFMER\i386\iw\wlbsprov.dl_
MOVE HFMER\i386\ia\wlbsprov.mf_ HFMER\i386\iadsw\&DEL/Q HFMER\i386\id\wlbsprov.mf_ HFMER\i386\is\wlbsprov.mf_ HFMER\i386\iw\wlbsprov.mf_
MOVE HFMER\i386\ia\wlbsprov.mo_ HFMER\i386\iadsw\&DEL/Q HFMER\i386\id\wlbsprov.mo_ HFMER\i386\is\wlbsprov.mo_ HFMER\i386\iw\wlbsprov.mo_
:: iadw
MOVE HFMER\i386\ia\basicsv.in_ HFMER\i386\iadw\&DEL/Q HFMER\i386\id\basicsv.in_ HFMER\i386\iw\basicsv.in_
MOVE HFMER\i386\ia\defltsv.in_ HFMER\i386\iadw\&DEL/Q HFMER\i386\id\defltsv.in_ HFMER\i386\iw\defltsv.in_
MOVE HFMER\i386\ia\dsup.in_ HFMER\i386\iadw\&DEL/Q HFMER\i386\id\dsup.in_ HFMER\i386\iw\dsup.in_
:: iapsw
MOVE HFMER\i386\drvindex.inf HFMER\i386\iapsw\&DEL/Q HFMER\i386\ia\drvindex.inf HFMER\i386\ip\drvindex.inf HFMER\i386\is\drvindex.inf HFMER\i386\iw\drvindex.inf
MOVE HFMER\i386\ia\e100bnt5.sy_ HFMER\i386\iapsw\&DEL/Q HFMER\i386\ip\e100bnt5.sy_ HFMER\i386\is\e100bnt5.sy_ HFMER\i386\iw\e100bnt5.sy_
MOVE HFMER\i386\ia\hptxnt5.sy_ HFMER\i386\iapsw\&DEL/Q HFMER\i386\ip\hptxnt5.sy_ HFMER\i386\is\hptxnt5.sy_ HFMER\i386\iw\hptxnt5.sy_
MOVE HFMER\i386\ia\ibmfent5.sy_ HFMER\i386\iapsw\&DEL/Q HFMER\i386\ip\ibmfent5.sy_ HFMER\i386\is\ibmfent5.sy_ HFMER\i386\iw\ibmfent5.sy_
MOVE HFMER\i386\ia\netcpqg.in_ HFMER\i386\iapsw\&DEL/Q HFMER\i386\ip\netcpqg.in_ HFMER\i386\is\netcpqg.in_ HFMER\i386\iw\netcpqg.in_
MOVE HFMER\i386\ia\netcpqi.in_ HFMER\i386\iapsw\&DEL/Q HFMER\i386\ip\netcpqi.in_ HFMER\i386\is\netcpqi.in_ HFMER\i386\iw\netcpqi.in_
MOVE HFMER\i386\ia\netel90x.in_ HFMER\i386\iapsw\&DEL/Q HFMER\i386\ip\netel90x.in_ HFMER\i386\is\netel90x.in_ HFMER\i386\iw\netel90x.in_
MOVE HFMER\i386\ia\scsi.in_ HFMER\i386\iapsw\&DEL/Q HFMER\i386\ip\scsi.in_ HFMER\i386\is\scsi.in_ HFMER\i386\iw\scsi.in_
:: iasw
MOVE HFMER\i386\ia\hivesft.inf HFMER\i386\iasw\&DEL/Q HFMER\i386\is\hivesft.inf HFMER\i386\iw\hivesft.inf
MOVE HFMER\i386\ia\hivesys.inf HFMER\i386\iasw\&DEL/Q HFMER\i386\is\hivesys.inf HFMER\i386\iw\hivesys.inf
:: iaw
MOVE HFMER\i386\ia\dosnet.inf HFMER\i386\iaw\&DEL/Q HFMER\i386\iw\dosnet.inf
MOVE HFMER\i386\ia\syssetup.in_ HFMER\i386\iaw\&DEL/Q HFMER\i386\iw\syssetup.in_
:: ips
MOVE HFMER\i386\ip\basicsv.in_ HFMER\i386\ips\&DEL/Q HFMER\i386\is\basicsv.in_
MOVE HFMER\i386\ip\defltsv.in_ HFMER\i386\ips\&DEL/Q HFMER\i386\is\defltsv.in_
MOVE HFMER\i386\ip\dsup.in_ HFMER\i386\ips\&DEL/Q HFMER\i386\is\dsup.in_
MOVE HFMER\i386\ip\setupreg.hiv HFMER\i386\ips\&DEL/Q HFMER\i386\is\setupreg.hiv

:: modyfing update.inf
@ECHO OFF>update.txt
FOR /F "tokens=* delims= " %%I IN (update.inf) DO (
IF "%%I"=="CatalogFile = sp4.cat" (
>>update.txt ECHO ThisServicePackBuild = 1
) ELSE (
ECHO %%I>>update.txt
)
)
@ECHO OFF>update2.txt
FOR /F "tokens=* delims= " %%I IN (update.txt) DO (
IF "%%I"=="MaxNtServicePackVersion = 1024" (
>>update2.txt ECHO MaxNtServicePackVersion = 1536
) ELSE (
ECHO %%I>>update2.txt
)
)
@ECHO OFF>update3.txt
FOR /F "tokens=* delims= " %%I in (update2.txt) do (
IF "%%I"=="ThisServicePackVersion = 1024" (
>>update3.txt ECHO ThisServicePackVersion = 1536
) ELSE (
ECHO %%I>>update3.txt
)
)

:: replacing original SP files with Gurgelmeyer
XCOPY/SY TOOLS\SP51 HFMER\i386 >NUL

:: updating sp4.cab
ECHO.&ECHO Unpacking sp4.cab...&ECHO.
MD TEMP\sp4cab&EXPAND -F:* HFMER\i386\new\sp4.cab TEMP\sp4cab >NUL
FOR /F %%I IN ('DIR/B TEMP\sp4cab') DO (
IF EXIST HFMER\%%I (
ECHO Processing %%I
XCOPY/DY HFMER\%%I TEMP\sp4cab\ >NUL
)
)
ECHO.&ECHO Repacking sp4.cab...
CABARC -m LZX:21 N HFMER\i386\new\sp4.cab TEMP\sp4cab\*.* >NUL
RD/Q/S TEMP\sp4cab >NUL

:: updating wms4.cab
ECHO.&ECHO.&ECHO Unpacking wms4.cab&ECHO.
MD TEMP\wms4cab&EXPAND -F:* HFMER\i386\wms4.cab TEMP\wms4cab >NUL
IF EXIST HFMER\WMS (
FOR /F %%I IN ('DIR/B HFMER\WMS') DO (
IF EXIST HFMER\%%I (
XCOPY/DY HFMER\WMS\%%I HFMER\ >NUL
DEL/Q HFMER\WMS\%%I
)
)
)
FOR /F %%I IN ('DIR/B TEMP\wms4cab') DO (
IF EXIST HFMER\WMS\%%I (
ECHO Processing %%I
XCOPY/DY HFMER\WMS\%%I TEMP\wms4cab\ >NUL
)
IF EXIST HFMER\%%I (
ECHO Processing %%I
XCOPY/DY HFMER\%%I TEMP\wms4cab\ >NUL
)
)
ECHO.&ECHO Repacking wms4.cab...
CABARC -m LZX:21 N HFMER\i386\wms4.cab TEMP\wms4cab\*.* >NUL
RD/Q/S TEMP\wms4cab >NUL

:: updating non-compressed SP files
ECHO.&ECHO.&ECHO Verifying non-compressed Service Pack files...&ECHO.

:: updating i386\system32 (ntdll.dll)
FOR /F %%I IN ('DIR/B HFMER\i386\system32') DO (
IF EXIST HFMER\uniproc\%%I (
XCOPY/DY HFMER\uniproc\%%I HFMER\ >NUL
)
IF EXIST HFMER\%%I (
ECHO Processing %%I
XCOPY/DY HFMER\%%I HFMER\i386\system32\ >NUL
)
)
:: updating i386\uniproc
FOR /F %%I IN ('DIR/B HFMER\i386\uniproc') DO (
IF EXIST HFMER\uniproc\%%I (
ECHO Processing %%I
XCOPY/DY HFMER\uniproc\%%I HFMER\i386\uniproc\ >NUL&DEL/Q HFMER\uniproc\%%I >NUL
)
)
:: updating i386
FOR /F %%I IN ('DIR/A-D/B HFMER\i386') DO (
IF EXIST HFMER\%%I (
ECHO Processing %%I
XCOPY/DY HFMER\%%I HFMER\i386\ >NUL&DEL/Q HFMER\%%I >NUL
)
)
:: updating compressed SP files
ECHO.&ECHO.&ECHO Verifying compressed Service Pack files...&ECHO.

:: updating i386
FOR /F %%I IN ('DIR/A-D/B HFMER\i386\*.*_') DO (
EXPAND -R HFMER\i386\%%I TEMP\ >NUL
FOR /F %%I IN ('DIR/A-D/B TEMP') DO (
IF EXIST HFMER\%%I (
ECHO Processing i386\%%I
XCOPY/DY HFMER\%%I TEMP\ >NUL&DEL/Q HFMER\%%I >NUL
MAKECAB /D CompressionMemory=21 /D CompressionType=LZX TEMP\%%I /L HFMER\i386 >NUL
)
DEL/Q/S TEMP\%%I >NUL
)
)
:: updating i386\lang\chs
FOR /F %%I IN ('DIR/A-D/B HFMER\i386\lang\chs\*.*_') DO (
EXPAND -R HFMER\i386\lang\chs\%%I TEMP\ >NUL
FOR /F %%I IN ('DIR/A-D/B TEMP') DO (
IF EXIST HFMER\%%I (
ECHO Processing i386\lang\chs\%%I
XCOPY/DY HFMER\%%I TEMP\ >NUL&DEL/Q HFMER\%%I >NUL
MAKECAB /D CompressionMemory=21 /D CompressionType=LZX TEMP\%%I /L HFMER\i386\lang\chs >NUL
)
DEL/Q/S TEMP\%%I >NUL
)
)
:: updating i386\lang\cht
FOR /F %%I IN ('DIR/A-D/B HFMER\i386\lang\cht\*.*_') DO (
EXPAND -R HFMER\i386\lang\cht\%%I TEMP\ >NUL
FOR /F %%I IN ('DIR/A-D/B TEMP') DO (
IF EXIST HFMER\%%I (
ECHO Processing i386\lang\cht\%%I
XCOPY/DY HFMER\%%I TEMP\ >NUL&DEL/Q HFMER\%%I >NUL
MAKECAB /D CompressionMemory=21 /D CompressionType=LZX TEMP\%%I /L HFMER\i386\lang\cht >NUL
)
DEL/Q/S TEMP\%%I >NUL
)
)
:: updating i386\lang\jpn
FOR /F %%I IN ('DIR/A-D/B HFMER\i386\lang\jpn\*.*_') DO (
EXPAND -R HFMER\i386\lang\jpn\%%I TEMP\ >NUL
FOR /F %%I IN ('DIR/A-D/B TEMP') DO (
IF EXIST HFMER\%%I (
ECHO Processing i386\lang\jpn\%%I
XCOPY/DY HFMER\%%I TEMP\ >NUL&DEL/Q HFMER\%%I >NUL
MAKECAB /D CompressionMemory=21 /D CompressionType=LZX TEMP\%%I /L HFMER\i386\lang\jpn >NUL
)
DEL/Q/S TEMP\%%I >NUL
)
)
:: updating i386\lang\kor
FOR /F %%I IN ('DIR/A-D/B HFMER\i386\lang\kor\*.*_') DO (
EXPAND -R HFMER\i386\lang\kor\%%I TEMP\ >NUL
FOR /F %%I IN ('DIR/A-D/B TEMP') DO (
IF EXIST HFMER\%%I (
ECHO Processing i386\lang\kor\%%I
XCOPY/DY HFMER\%%I TEMP\ >NUL&DEL/Q HFMER\%%I >NUL
MAKECAB /D CompressionMemory=21 /D CompressionType=LZX TEMP\%%I /L HFMER\i386\lang\kor >NUL
)
DEL/Q/S TEMP\%%I >NUL
)
)
:: updating i386\new
FOR /F %%I IN ('DIR/A-D/B HFMER\i386\new\*.*_') DO (
EXPAND -R HFMER\i386\new\%%I TEMP\ >NUL
FOR /F %%I IN ('DIR/A-D/B TEMP') DO (
IF EXIST HFMER\%%I (
ECHO Processing i386\new\%%I
XCOPY/DY HFMER\%%I TEMP\ >NUL&DEL/Q HFMER\%%I >NUL
MAKECAB /D CompressionMemory=21 /D CompressionType=LZX TEMP\%%I /L HFMER\i386\new >NUL
)
DEL/Q/S TEMP\%%I >NUL
)
)
:: updating i386\uniproc
FOR /F %%I IN ('DIR/A-D/B HFMER\i386\uniproc\*.*_') DO (
EXPAND -R HFMER\i386\uniproc\%%I TEMP\ >NUL
FOR /F %%I IN ('DIR/A-D/B TEMP') DO (
IF EXIST HFMER\uniproc\%%I (
ECHO Processing i386\uniproc\%%I
XCOPY/DY HFMER\uniproc\%%I TEMP\ >NUL&DEL/Q HFMER\uniproc\%%I >NUL
MAKECAB /D CompressionMemory=21 /D CompressionType=LZX TEMP\%%I /L HFMER\i386\uniproc >NUL
)
DEL/Q/S TEMP\%%I >NUL
)
)

:: cleaning HFMER (empty folders)
RD/Q/S HFMER\uniproc >NUL
RD/Q/S HFMER\WMS >NUL

:: cleaning TEMP
RD/Q/S TEMP >NUL



:: COPYING NEW FILES STARTS HERE! REQUIRES EDITING UPDATE.INF / UPDATE.VER! SKIP IF CAN'T DO !!!



:: moving new files to i386\sp6
ECHO.&ECHO.&ECHO Copying new files to i386\SP6...&ECHO.

IF NOT EXIST HFMER\i386\sp6 MD HFMER\i386\sp6
FOR /F %%I IN ('DIR/A-D/B HFMER') DO (
ECHO Copying %%I
XCOPY HFMER\%%I HFMER\i386\sp6 >NUL&DEL/Q HFMER\%%I >NUL
)

:: moving HFMER\update\*.* to HFMER\i386\update\
IF EXIST HFMER\update\eula.txt MOVE/Y HFMER\update\eula.txt HFMER\i386\update\eula.txt
IF EXIST HFMER\update\update.inf MOVE/Y HFMER\update\update.inf HFMER\i386\update\update-sp6.inf
IF EXIST HFMER\update\update.ver MOVE/Y HFMER\update\update.ver HFMER\i386\update\update-sp6.ver

:: copying catalogs from HFMER\update to HFMER\i386\svcpack
ECHO.&ECHO.&ECHO Copying catalog files to Service Pack folder...&ECHO.

IF EXIST HFMER\update\*.cat (
FOR /F %%I IN ('DIR/A-D/B HFMER\update\*.cat') DO (
IF NOT EXIST HFMER\i386\svcpack MD HFMER\i386\svcpack
ECHO Copying %%I
XCOPY HFMER\UPDATE\%%I HFMER\i386\svcpack\ >NUL&DEL/Q HFMER\UPDATE\%%I >NUL
)
)

:: comparing SP6 folder with original W2K i386
ECHO.&ECHO.&ECHO Verifying new files...&ECHO.

IF EXIST TEMP RD/Q/S TEMP
MD TEMP\sp6 HFMER\i386\sp6\new

XCOPY HFMER\i386\sp6\*.* TEMP\sp6 >NUL
DEL/Q HFMER\i386\sp6\*.* >NUL

:: sorting compressed files
FOR /F %%I IN ('DIR/A-D/B W2KCD\i386\*.*_') DO (
EXPAND -R W2KCD\i386\%%I TEMP\ >NUL
FOR /F %%I IN ('DIR/A-D/B TEMP') DO (
IF EXIST TEMP\sp6\%%I (
ECHO Processing %%I
XCOPY/DY TEMP\%%I TEMP\sp6\ >NUL
MAKECAB /D CompressionMemory=21 /D CompressionType=LZX TEMP\sp6\%%I /L HFMER\i386\sp6\ >NUL
DEL/Q TEMP\sp6\%%I >NUL
)
DEL/Q TEMP\%%I >NUL
)
)

:: sorting non-compressed files
FOR /F %%I IN ('DIR/A-D/B W2KCD\i386') DO (
FOR /F %%I IN ('DIR/B TEMP\sp6') DO (
IF EXIST W2KCD\i386\%%I (
ECHO Processing %%I
XCOPY/DY W2KCD\i386\%%I TEMP\sp6\ >NUL
)
XCOPY/DY TEMP\%%I HFMER\i386\sp6\%%I >NUL&DEL/Q TEMP\sp6\%%I
)
)

XCOPY TEMP\sp6\*.* HFMER\i386\sp6\new\ >NUL

:: cleaning TEMP
RD/Q/S TEMP

EXIT

The main points are:

- To remove all duplicate files from the original SP. A lot of files from ia/id/is/ip folders overlap each other. The method I use to dedupe them is to make new folders (iads, iadw, etc.) and move shared files according to the edition of 2K they are related to. After that the update.inf has to be changed too (this part is not ready yet).

- Replace installer files with the ones from Gurgelmeyer's USP5 which ignore M$ digital signatures.

- Update SP files with new versions. This is the most problematic part. First of all, it's easy to update files that are already in SP4. They can just be directly replaced and no changed to the update.inf are needed. The problem is with those files that do not originally belong to SP4. In order to add them, the update.inf has to be edited and it is complicated as it can't be done by just merging the update.inf from HFMER\update with the one from SP4. There are additional sections which are related to the /integrate switch ([servicePackFiles], etc.) and new files must be placed there in order to get integrated. These sections are empty in normal (non-SP) updates. The other issue is that SP4's update.inf is old and its structure is a little different than update.infs from newer updates. By processing them by jaclaz's script many unnecessary and overlapping lines get inserted. The way to fix it would be to 'update' the SP4's update.inf to make it more similar to the newer ones. Some of the older updates are also affected by this issue. The same 'updating' thing probably must be done to the update.inf merged by the script. I'll have to work on it separately.

- New files (not belonging to the original SP4) are placed in a new folder (i386\SP6) to have them separated from the rest. They are also checked against the original W2K CD i386 files to know which of them can be compressed (makecab) and which not. Files which are not present either in SP4 or the 2K CD get copied to i386\SP6\new.

That's all for now. There are still many things to do, especially related to the merged update.inf file. I'm open to any ideas about how to change and what to improve in the script.

Edited by tomasz86
0

Share this post


Link to post
Share on other sites

I have a problem and don't know how to solve it.

Why doesn't GOTO work here?

splitinf.cmd update.inf

GOTO :SP

There is no problem if the first line is disabled

REM splitinf.cmd update.inf

GOTO :SP

The script just does splitinf and stops... As far as I remember it worked before but now it doesn't :} There are no errors on the screen. It behaves as it there was EXIT after the splitinf line.

Edited by tomasz86
0

Share this post


Link to post
Share on other sites

In a rush right now so don't have time to look up the syntax, but try executing the first line through a CALL statement. That should force return to execute the next line.

Cheers and Regards

Edited by bphlpt
0

Share this post


Link to post
Share on other sites

It works :thumbup

0

Share this post


Link to post
Share on other sites

INF UpdateInis is perfect for this

Tell me the path+name the file I can give you some examples

UpdateIniFields

[update-inifields-section-name]

ini-file, ini-section, profile-name,(old-field), (new-field),(flags)

Replaces, adds, and deletes fields in the value of a given INI entry. Unlike the Update INI File section

type, this type of section replaces, adds, or deletes portions of a value in an INI file entry rather than the

whole value. The section name, update-inifields-section-name, must appear in the UpdateIniFields item

in an Install section of the INF file.

ini-file

Name of the INI file containing the entry to change. For more information about specifying the INI

filename, see the topic that describes the Update INI File section type.

ini-section

Name of the INI file section containing the entry to change.

profile-name

Name of the entry to change.

old-field

Field value to delete.

new-field

Field value to add, if not already there.

flags

Specifies whether to treat the old-field and new-field parameters as if they have a wild card character or

not and/or what separator character to use when appending a new field to an INI file entry. Can be any

of these values:

Value Meaning

0 (Default) Treat "*" character literally when matching fields, and not as a wild card

character. Use blank (" ") as a separator when adding a new field to an entry.

1 Treat "*" character as a wild card character when matching fields. Use blank (" ") as a

separator when adding a new field to an entry.

2 Treat "*" character literally when matching fields, and not as a wild card character. Use

comma (",") as a separator when adding a new field to an entry.

3 Treat "*" character as a wild card character when matching fields. Use comma (",") as a

separator when adding a new field to an entry.

Any comments in the INI file line are removed as they might not be applicable after changes. When

looking for fields in the line in the INI file, spaces, tabs and commas are used as field delimiters.

However, a space is used as the separator when the new field is appended to the line.

Edited by ricktendo64
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.