http://paste.pound-python.org/show/941/

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!

Banjoplucker.

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 = f.read(int(carved))

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 = f.read(int(carved))
                for each_file in listing:
                    doc_wp = open(os.path.join(root,each_file), 'ab')
                    doc_wp.write(out_block)
                    doc_wp.close()

http://paste.pound-python.org/show/1137/

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()
g.close()
h.close()

for count,(header,carved) in enumerate(zip(header_lines,carve_size)):
    f.seek(int(header))
    out_block = f.read(int(carved))
    outfile = open('wpdocs\\file%03d.wp'%count, 'wb')
    outfile.write(out_block)
    outfile.close()
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.