Creating a global master file.

Hi everybody,

I hope you are well and can help.

I have a top folder. Let's call is "Master".
Underneath this folder, I have many subfolders, of unknown number, but all will contain 3 files, with similar naming convention.
So, the folder structure could look like this..

 Parent      Child
 Folder      Folder   3 files of similar naming convention

    |_______ ad
    |_______ batchfile
    |_______ sccm
    |_______ vmware

 As you can see, the naming conventions for the 3 files are:


 where "*" is the same name as the folder name given for the child folder these files reside in.


What I want to do is the following:

I want to create a script, that will create a text file that contains the contents of every 3of3_master_*.txt in the above folder structure.

So, for example, in the above scenario, this is how it would look....

1.Create a text file called 'GLOBAL-MASTER.txt'.
2.Read every subfolder of the top folder 'Master', looking for a file called '3of3_master_*.txt'
3.For each file 3of3_master_*.txt found, read its contents and copy into the 'GLOBAL-MASTER.txt' file created in step 1.
4.Leave a line or 2 blank space between each '3of3_master_*.txt' in the new GLOBAL-MASTER.txt file.

Here for example, are the contents of each file targetted...

------------------------------------------------- 3of3_master_ad.txt

Master: ad

------------------------------------------------- 3of3_master_batchfile.txt

Master: batchfile

------------------------------------------------- 3of3_master_sccm.txt

Master: sccm
deployment type;  

------------------------------------------------- 3of3_master_vmware.txt

Master: vmware

The output by running the script will be like below.

=====================================================================  GLOBAL-MASTER.txt

Master: ad

Master: batchfile

Master: sccm
deployment type;  

Master: batchfile

So, you can see, that the script will create a text file called 'GLOBAL-MASTER.txt, which will contain the contents of all 3of3_master_*.txt in the above folder structure.

Any help greatly appreciated.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

The shell "glob" operator will do the subdirectory search for you easily enough:

cat Master/*/3of3_master*.txt >GLOBAL-MASTER.txt

Open in new window

But you want to decorate the GLOBAL-MASTER.txt with extra spaces, so something more like

for file (Master/*/3of3)master*.txt )
cat $file
echo ""
echo ""

Open in new window

This isn't exactly the contents of your example, but maybe it's close enough?
Simon336697Author Commented:
Hi jcmg,
Thanks so much for that.
That looks unix like.

Im more of a wintel person.
NVITEnd-user supportCommented:
rem @echo off
rem - Copies contents of found files into master FNGlobal file
rem - FNGlobal is placed in the %temp% folder.
rem - Adjust TopDirName and TopDir values as needed.

set FNAll=%temp%\%~n0_All.txt
set FNGlobal=%temp%\%~n0_GLOBAL-MASTER.txt
set TopDirName=master
set TopDir=c:\%TopDirName%

if exist "%FNGlobal%" del "%FNGlobal%"
type nul>"%FNGlobal%"

pushd "%TopDir%"
dir /b /s "3of3_%TopDirName%*.txt" > "%FNAll%"
for /f %%a in (%FNAll%) do (
  copy /a "%FNGlobal%"+"%%a" "%FNGlobal%">nul
  >> "%FNGlobal%" echo.
  >> "%FNGlobal%" echo.

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Simon336697Author Commented:
thx so much and sorry for the delay. happy christmas to all.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.