Split multi-contact .vcf address book into individual .vcf’s

Split multi-contact .vcf address book into individual .vcf’s

Moving contacts from one phone to another is a tricky business. And when the manufacturers of the said two phones are different, this process quickly turns into a pain in the b*tt.

It’s a known fact that Android (and, weirdly, older Sony-Ericsson) phones export their contacts as a single multi-contact vcf file. And it’s also a know (and hated) fact that Nokia’s (otherwise great) Suite program can only import single-contact vcards.

So your options here are to either manually split that multi-(in the hundreds)-contact file into separate vcf’s, one for each contact so that they can be imported into a Nokia, or to use the little script below.

##################################################################
# AmandaVCD is a free software which was made with the help of:  #
#                                                                #
#          @xel (programming)                                    #
#          @xel (designing)                                      #
#                                                                #
##################################################################
fname = raw_input('name of file: ')

fopen = open(fname, 'r')

begincard = 'BEGIN:VCARD'
endcard = 'END:VCARD'
i = 0
cutline = 'ggghtekgqp'
while not cutline == '':
    if cutline[0:11] == begincard:
        i=i+1
        filnam='%i.vcf'%(i)
        testopen = open(filnam, 'w')
        while not cutline[0:9] == endcard:
            testopen.write(cutline)
            cutline = fopen.readline()
         
        if cutline[0:9] == endcard:
	    testopen.write('END:VCARD')
            testopen.close()
    cutline = fopen.readline()
#EOF

This is a Python script. Save the code to split.py (for example), make it executable with chmod +x split.py and run it with ./split.py.

It will ask for the name of the multi-contact vcf (should be placed in the same folder) and will save a multitude of numbered single-contact vcf’s just waiting to be imported into a Nokia.

3 Comments

  1. Hey there! Did you change the script to say:

    begincard = ‘begin:vcard’
    endcard = ‘end:vcard’

    instead of how it says:

    begincard = ‘BEGIN:VCARD’
    endcard = ‘END:VCARD’

    When I did this (see my original comment), the capitalization had to match for the script to work.

    Miss H
  2. Hello, thanks for the python script. I am wanting to convert the single multi-contact vcf file that Thunderbird generates into single contact files. The aim is to get these onto my Android phone. The phone does not seem to like the format of the single vcf file generated by Thunderbird but will happily import multiple single contact vcfs: I sent all my contacts from a Nokia E7 via bluetooth and it added them to the Android contacts one by one without a problem.

    I generally update all my contacts on my PC and so if I could periodically export them direct to my phone without using any 3rd party syncing or cloud service or Google that would be great.

    I noticed that the Thunderbird multi vcf and an Android multi vcf have a different format.
    When I run split.py on the Android file it works fine but on the Thunderbird file it prompts for the file name and after I input this it concludes running without actually outputting any single files or giving any form of error.

    Here is an example of a Thunderbird vcf entry:

    begin:vcard
    fn:Homr, Jan
    n:Homr;Jan
    email;internet:janddddd@gmail.com
    tel;work:+2755555555555
    tel;fax:+27214444444444
    tel;cell:+27823333333333
    note:ABSA
    version:2.1
    end:vcard

    There is a difference between this and the Android entries and I think maybe the script was not written to parse this kind of entry. I have tried to see if I can modify the script but am no programmer so am hoping you can save me some pain with this.

    Greg
  3. Oh my gosh, thank you thank you thank you!!! You just saved me hours of manually splitting a VCF file!

    I finally was able to turn my Excel/Libre Office spreadsheet into separate vcards. First, I saved the spreadsheet as a CSV file. Second, I imported it into Thunderbird mail client, which turned it into one massive VCF file. My little Nokia E63 only reads the first contact in a file, so the third step was to use your lovely script to split up that one big VCF file into over a hundred smaller ones.

    Notes: My computer is using Python 3.4.3, so I had to change “raw_input” to “input” per instructions elsewhere online. When I pasted the code into a new file, it complained about inconsistent tabs/spaces, so I followed directions for my editor to make everything spaces. Also, my vcard file had lowercase “BEGIN:VCARD” and “END:VCARD”, so I changed those in the script, and then it worked!!!

    Miss H

Leave a Reply