I would like to merge a few dat files in a directory and exclude certain dat files as previously I have already marked out the files that I need and do not need. Below is an example of my codes

def onAssemble(self,event): 
    with open("index.dat", 'r') as file: 
        data = file.readlines() 
        print data 
        i = 1 
        fn = "python.dat" 
        f = open(fn) 
        output = [] 
        for line in data: 
            if not "*" in line: 
                output.append(line) 
        f.close() 
        t = open(fn, 'w')
        t.writelines(output) 
        t.close()

Python is indention sensitive, I tried to fix your code. Did I guess it right.

So what is your question?

Yes thank you very much. Sorry for the indention part. My questions is how do you search through a folder and only append certain dat files together and exclude the rest. For example there are 7 .dat files and I only want to append 4 of it together and not all.

Don't use file as a variable name since file() is function in python2
You don't do anything with f

What do you mean by that? Can you further elaborate?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.