Link to home
Start Free TrialLog in
Avatar of Simon336697
Simon336697Flag for Australia

asked on

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

 Master
    |_______ ad
                      |_________1of3_workings_ad.txt
                      |_________2of3_sorted_ad.txt
                      |_________3of3_master_ad.txt
    |_______ batchfile
                      |_________1of3_workings_batchfile.txt
                      |_________2of3_sorted_batchfile.txt
                      |_________3of3_master_batchfile.txt
    |_______ sccm
                      |_________1of3_workings_sccm.txt
                      |_________2of3_sorted_sccm.txt
                      |_________3of3_master_sccm.txt
    |_______ vmware
                      |_________1of3_workings_vmware.txt
                      |_________2of3_sorted_vmware.txt
                      |_________3of3_master_vmware.txt


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

 1of3_workings_*.txt
 2of3_sorted_*.txt
 3of3_master_*.txt

 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....

script.cmd
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
-------------------------------------------
 
item1,item2,item3;  


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

-------------------------------------------
Master: batchfile
-------------------------------------------
 
batch,token;  



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

-------------------------------------------
Master: sccm
-------------------------------------------
 
deployment type;  


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

-------------------------------------------
Master: vmware
-------------------------------------------
 
esx,vsphere;  



The output by running the script will be like below.



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

 
-------------------------------------------
Master: ad
-------------------------------------------
 
item1,item2,item3;  


 
-------------------------------------------
Master: batchfile
-------------------------------------------
 
batch,token;  


-------------------------------------------
Master: sccm
-------------------------------------------
 
deployment type;  


-------------------------------------------
Master: batchfile
-------------------------------------------
 
esx,vsphere;  




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.
SOLUTION
Avatar of jmcg
jmcg
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Simon336697

ASKER

Hi jcmg,
Thanks so much for that.
That looks unix like.

Im more of a wintel person.
ASKER CERTIFIED SOLUTION
Avatar of NVIT
NVIT
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thx so much and sorry for the delay. happy christmas to all.