Having trouble getting a loop to write to a series of newly created sequential blank .wp files. Grateful for any help, thank you.

Regards & a Happy New Year!


Some thoughts:

What are you accomplishing with:

for i in range(n):
    open('wpdocs\\file' + str(i) + '.wp', 'wb').close()

"f" is your bitstream.
This reads up to the end of the stream:

out_block =

Is "path" supposed to be quotated?

doc_wp = open('path', 'wb')

doc_wp writes to itelf.

Maybe this might give you a clue. doc_wp = open('path', 'wb') Opens a file with name: path

while out_block:
                listing = os.listdir(root)
                out_block =
                for each_file in listing:
                    doc_wp = open(os.path.join(root,each_file), 'ab')

need to read from 2 separate lists simultaneously within a for loop, so that line 1 from file 1 is used with line 1 from file 2, then line 2 from file 1 is used with line 2 from file 2 etc. through the incrementation. Current code causes each line to be used several times before stepping onto the next line. The intention is to extract defined file lengths of data from specific offset locations.

g = open("images\\truesignatures.log", "r")  # reads header position file
header_lines = g.readlines()
h = open("images\\wpfilesize.log", "r") # reads in the list of file sizes for application in carve interation
carve_size = h.readlines()

for count,(header,carved) in enumerate(zip(header_lines,carve_size)):
    out_block =
    outfile = open('wpdocs\\file%03d.wp'%count, 'wb')