Jump to content
Sign in to follow this  
Home Bunny

Convert vCard Files to one CSV File

Recommended Posts

Home Bunny

Hi,

What does this script do?

If you have copied all your NOKIA Telephone Contacts with bluetooth to your Computers HardDrive, you wil have 200+ seperate vCard Files.

How can you import these into Outlook (or another mail program)? One By one?

This script will merge all these small files into one CSV file.

This is a script without GUI!

configuration is done into the the 3 first lines.

$SearchFolder = "C:\Temp\Nokia\Contacts\"
$SearchExt = "vcf"
$SaveToFile = "C:\Temp\Nokia\Contacts\Export.csv"


Dim $H_Begin, $H_Version, $H_Name, $H_TelWork, $H_FaxWork, $H_End

$search = FileFindFirstFile($SearchFolder & "*." & $SearchExt)

; Check if the search was successful
If $search = -1 Then
    MsgBox(0, "Error", "No files/directories matched the search pattern")
    Exit
EndIf

$SaveFile = FileOpen( $SaveToFile, 2 )

$WriteLine = "BEGIN" & "," & "VERSION" & "," & "NAME" & "," & "WORK_TEL" & "," & "WORK_FAX" & "," & "END"
FileWriteLine($SaveFile,$WriteLine)

While 1
    $file = FileFindNextFile($search) 
    If @error Then ExitLoop
    
;~   MsgBox(4096, "File:", $file)
    $VCARD_File = FileOpen($SearchFolder & $file, 0)
    
    
; Check if file opened for reading OK
    If $VCARD_File = -1 Then
        MsgBox(0, "Error", "Unable to open file." & $VCARD_File)
        Exit
    EndIf
    
    $H_Begin = ""
    $H_Version = ""
    $H_Name = ""
    $H_TelWork = ""
    $H_FaxWork = ""
    $H_End = "" 
    
; Read in lines of text until the EOF is reached
    While 1
        $line = FileReadLine($VCARD_File)
        If @error = -1 Then ExitLoop

        $Header = StringTrimRight($line, StringLen($line) - StringInStr($line,":") + 1 )
                                                            
        $result = StringTrimLeft($line,StringLen($Header) + 1 )
        
        Select
            Case $header = "BEGIN"
                $H_Begin = $result
            Case $header = "VERSION"
                $H_Version = $result
            Case $header = "N"
                $H_Name = StringReplace( $result,";", "")
            Case $header = "TEL;VOICE"
                $H_TelWork = $result
            Case $header = "TEL;FAX"
                $H_FaxWork = $result
            Case $header = "END"
                $H_End = $result
        EndSelect
    Wend
    
    $WriteLine = $H_Begin & "," & $H_Version & "," & $H_Name & "," & $H_TelWork & "," & $H_FaxWork & "," & $H_End
    
    FileWriteLine($SaveFile,$WriteLine)
    
    FileClose($VCARD_File)
    
    
WEnd

; Close the search handle
FileClose ( $search )
FileClose ( $SaveFile )

Share this post


Link to post
Share on other sites
microera

Nice!!

I have problem to create form one VCF file (whic have many single VCF cards):

------------------------------------------------------------- all_vcf_in_one_file.vcf

BEGIN:VCARD

VERSION:2.1

N:;?agar ?tefka;;;

TEL:041802581

NOTE:

END:VCARD

BEGIN:VCARD

VERSION:2.1

N:;?agar Bojan;;;

TEL;CELL:031820666

NOTE:

END:VCARD

BEGIN:VCARD

VERSION:2.1

N:;?agar Erik;;;

TEL;CELL:031613595

NOTE:

END:VCARD

-------------------------------------------------------------------------------------

when I try to upload with nokia pc suite only one vcf card is instered to nokia!

:D

anybody make batch file wich create more vcf single files form one vcf file (wich have many visit cards(VCF) like example above?

So: I need extract from one vcf file to more vcf files. Each file begin with BEGIN:VCARD and end with: END:VCARD

In above example ... 3 files!

Edited by microera

Share this post


Link to post
Share on other sites
microera

this example extract vCards from one .vcf file (if exists many vcards in it):

1st: copy .vcf file to input.vcf

extracting vCards are numbured from 1 to _.vcf

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.1.1 (beta)
 Author:         myName / modified: microera

 Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here

    $inputfile ="input.vcf"


Dim $H_Begin, $H_Version, $H_Name, $H_TelWork, $H_FaxWork, $H_End


    
;~   MsgBox(4096, "File:", $file)
    $VCARD_File = FileOpen($inputfile, 0)
    
    
; Check if file opened for reading OK
    If $VCARD_File = -1 Then
        MsgBox(0, "Error", "Unable to open file." & $VCARD_File)
        Exit
    EndIf
    
    $H_Begin = ""
    $H_End = "" 
    
    $counterV=0             ;vCard counter
    $New_vCard=0            ;flag for begining of vCard
    
; Read in lines of text until the EOF is reached
    While 1
        
        $line = FileReadLine($VCARD_File)
        
        
        If @error = -1 Then ExitLoop

        $Header = StringTrimRight($line, StringLen($line) - StringInStr($line,":") + 1 )
                                                            
        $result = StringTrimLeft($line,StringLen($Header) + 1 )
        
        ;MsgBox(4096, "Header=", $Header )
        ;MsgBox(4096, "result=", $result )
        
        Select
            Case $header = "BEGIN"
                $H_Begin = $result

            Case $header = "END"
                $H_End = $result
        EndSelect
        
    
        if $H_Begin="VCARD" then 

            if $New_vCard=0 then 
                $counterV=$counterV+1
                $SaveFile = FileOpen( $counterV & ".vcf", 2 )
            EndIf   
            ;FileWriteLine($SaveFile,$line)
            $New_vCard=1            ;flag for begining vCard
        EndIf
        
        if $New_vCard=1 then FileWriteLine($SaveFile,$line)         ;if new vCARD then writeln(copy)

        if $H_End="VCARD" then 
            ;FileWriteLine($SaveFile,$line)                         ;last writelen(copy)
            FileClose ( $SaveFile )
            $New_vCard=0
            $H_Begin = ""
            $H_End = "" 
        EndIf
            
        
    Wend

    
    FileClose($VCARD_File)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.