Loop and merge all files w the same file name
Posted: 30 Oct 2013 12:21
I'm trying to write a bat script to loop in the folder and merge all the files with the same filename (extension as a wildcard) outputting the same filename but extension as txt for the merge file. Sometime there only 1 file so there no need to merge but i would still need it moved to the output folder. For example...
Current File:
TESTGMCS.000
TESTGMCS.001
TESTGMCS.002
TESTSMCS.000 (TESTSMCS.001 and TESTSMCS.002 does't currently exist but can some days)
TESTWMCS.000
TESTWMCS.001
TESTWMCS.002
TESTXMCS.000
TESTXMCS.001 (TESTCMCS.002 does't currently exist but can some days)
TESTCMCS.000 (TESTCMCS.001 and TESTCMCS.002 does't currently exist but can some days)
OutFiles Merged:
TESTGMCS.txt
TESTSMCS.txt
TESTWMCS.txt
TESTXMCS.txt
TESTCMCS.txt
Current File:
TESTGMCS.000
TESTGMCS.001
TESTGMCS.002
TESTSMCS.000 (TESTSMCS.001 and TESTSMCS.002 does't currently exist but can some days)
TESTWMCS.000
TESTWMCS.001
TESTWMCS.002
TESTXMCS.000
TESTXMCS.001 (TESTCMCS.002 does't currently exist but can some days)
TESTCMCS.000 (TESTCMCS.001 and TESTCMCS.002 does't currently exist but can some days)
OutFiles Merged:
TESTGMCS.txt
TESTSMCS.txt
TESTWMCS.txt
TESTXMCS.txt
TESTCMCS.txt
Code: Select all
@ECHO off
SET FILE1="\\hdrive\WS Reports\TESTGMCS.*"
SET FILE2="\\hdrive\WS Reports\TESTSMCS.*"
SET FILE3="\\hdrive\WS Reports\TESTWMCS.*"
SET FILE4="\\hdrive\WS Reports\TESTXMCS.*"
SET FILE5="\\hdrive\WS Reports\TESTCMCS.*"
copy %FILE1% "\\hdrive\WS Reports\Final\TESTGMCS.txt"
copy %FILE2% "\\hdrive\WS Reports\Final\TESTSMCS.txt"
copy %FILE3% "\\hdrive\WS Reports\Final\TESTWMCS.txt"
copy %FILE4% "\\hdrive\WS Reports\Final\TESTXMCS.txt"
copy %FILE5% "\\hdrive\WS Reports\Final\TESTCMCS.txt"