Click here to Skip to main content
15,902,189 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Input: I have more than 100 sample files. Each sample file has two different files has an extension of *.column' and *.datatypes

File1: Having two files *.column and *.datatypes I need to add two files into one file.

File2: Having two files *.column and *.datatypes I need to add two files into one file.
Like 100 files having *.column and *.datatypes, I need to add two files into one file.

sample data
Quote:
File1:columnnames dataypes
id int,
name string


Quote:
File2:column names dataypes
date date,
name string.


What I have tried:

i tried with:
Python
for name in os.listdir("C:\Python27"):
    if name.endswith(".column"):
        for file in name:
            file = os.path.join(name)
            joined = file+ "final"
            with open(joined,"w") as fout:
                filenames = glob.glob('*.column')
                for filename in filenames:
                    with open(filename) as f1:
                        for line in f1:
                            file_names = glob.glob('*.datatypes')
                            for filename in file_names:
                                with open(filename) as f2:
                                    for line in f2:
                                      for line1,line2 in zip(f1,f2):
                                         x = ("{0} {1} \n".format(line1.rstrip(),line2.rstrip()))
                                         y = x.strip()
                                         fout.write(y.strip() + ',\n') 


Quote:
But i got the output:
columnnames datatypes
id int,
name string,
date date,
name string
I want in separe for each individula files. Please assist me.
Posted
Updated 10-Sep-17 5:53am
v2
Comments
Richard MacCutchan 10-Sep-17 11:52am    
You should create two lists, one of each set of file extensions. You can then go through the lists in a single loop reading each pair of files and combining the data.
[no name] 10-Sep-17 12:38pm    
And how I can upvote this, as long you don't publish this as a solution?
Richard MacCutchan 10-Sep-17 14:40pm    
It is not a solution but a suggestion to get started.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900