i've a problem to split a joining multipe type of file

here's my code for joining two diff type file, pict file (jpg) and audio file(mp3)
an ouput is pict file contains audio file in it.
a problem is how do i check this file is joining file or not?
and how do i split this kind of file?
(suppose that spliting and joining code are separate)

import sys
import os

f = open("e:/Dev/1.jpg", "rb")
g = open("e:/Dev/2.mp3", "rb")
dataList = []
dataList.append(f.read())
dataList.append(g.read())
g.close()

data = f.read()
new = f.name
f = open(new, 'wb')
for data in dataList:
    f.write(data)
f.close()
os.remove(g.name)

Use tar or zip file.

thanks for your advice sir.
but i need more detail.

@tonyjv: sorry, but that isn't what i want.
in my case, joined file still can be accessed.
ex:
file 1: 1. jpg
file 2: 2.mp3
output file/joined file: 1.jpg (contain 2.mp3). this file can be accessed as image file.
note that a first file always be output file and can be accessed as usual.

a problem is how to split this joined file to be a original file. output should be 1st and 2nd input file.

You want to hide the second file ? Can you not leave only first file availble separately if it is needed to be accessesed directly with other apps?

Interesting this your use of name attribute, I have never used it myself. However I have everytime filename in variable for easy changing.

Edited 5 Years Ago by pyTony: n/a

yeah, i hide a second file in 1st file. please try to test my code if u want
do you mean that i should keep a first and joined file? i think that's not a good idea.

a main problem is stiil no answer. :(

Edited 5 Years Ago by DYP: n/a

I still do not understand your motivations, but you have basically two options:
1) You can split the joined file from saved lengths of each part
2) You can add separator file between each file with pattern not existing in any of files and split by that

Best would be not to use broken file format which looks kind of normal file, looks kind of criminal activity.

Comments
thanks for advice

I think you might be correct tonyjv, but in the same sence sometimes it's for educational purposes to. I can only see 2 reasons to want to do this and one is educational the other is malicious. Just remember if you send a file like that to anyone you might be sitting in a cell for a long period of time for a silly little experiment.

@predator78: of course, i'm doing this for educational purpose only. there is no intention to commit a crime.

my motivation is just to hide file in other file. but i have problem to split it to original file.
i have a question for both option.

1) where should i keep my saved length of each part? and how i call this variable of saved length?

2) i try to add a text file as a separator file. (size:10 byte data:'abcdefghij') a question is how do i know a position of this file in my new joined file?

thanks for your help.

Edited 5 Years Ago by DYP: n/a

i've finished changing my code.

this one for joining a file (hide 2nd file in 1st file)

import sys
import os

f = open("1.pdf", "rb") #file as a hider
g = open("2.mp3", "rb") #file you want to hide
h = open("c.txt", "wb") #separator file
h.write('abcdefghij')
h.close()
h = open("c.txt", "rb")
dataList = []
dataList.append(f.read())
dataList.append(h.read())
dataList.append(g.read())
g.close()
h.close()

data = f.read()
new = f.name
f = open(new, 'wb')
for data in dataList:
    f.write(data)
f.close()
os.remove(g.name)
os.remove(h.name)

and this one for bring back your file to original form.

import sys

f = open("1.pdf", "rb")
data = f.read()
z = list(data)

i = 0
while z[i]<>'a' or z[i+1]<>'b' or z[i+2]<>'c' or z[i+3]<>'d':
    i = i+1

bytes = len(data)
print bytes
inc = bytes - (i+10)
for j in range (i+10, bytes, inc):
    print j
    fn1 = open("hiddenfile", "wb")  #problem here!
    fn1.write(data[j:j+inc])
    fn1.close()
    
new = f.name
fn2 = open(new, "wb")
fn2.write(data[0:i])
fn2.close()
f.close()

but still i've a problem to using back a previous name of hidden file.
i'm using a new name "hiddenfile" instead.

any suggestion would be help.

Edited 5 Years Ago by DYP: n/a

problem solved!

hide.py

import sys
import os

f = open("1.mp3", "rb")
g = open("2.jpg", "rb")
h = open("c.txt", "wb")
h.write('abcde')
h.write(g.name)
h.write('fghij')
h.close()
h = open("c.txt", "rb")
dataList = []
dataList.append(f.read())
dataList.append(h.read())
dataList.append(g.read())
g.close()
h.close()

data = f.read()
new = f.name
f = open(new, 'wb')
for data in dataList:
    f.write(data)
f.close()
os.remove(g.name)
os.remove(h.name)

split.py

import sys

f = open("1.mp3", "rb")
data = f.read()
z = list(data)

i = 0
while z[i]<>'a' or z[i+1]<>'b' or z[i+2]<>'c' or z[i+3]<>'d':
    i = i+1

h = i+5
while z[h]<>'f' or z[h+1]<>'g' or z[h+2]<>'h' or z[h+3]<>'i':
    h = h+1

hidname = ''
for x in range (i+5,h,1):
    hidname = hidname + z[x]


bytes = len(data)
inc = bytes - (h+5)
for j in range (h+5, bytes, inc):
    fn1 = open(hidname, "wb")
    fn1.write(data[j:j+inc])
    fn1.close()
    
new = f.name
fn2 = open(new, "wb")
fn2.write(data[0:i])
fn2.close()
f.close()
This question has already been answered. Start a new discussion instead.