Jump to content
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
JLogan3o13

@ElijahWright did you not notice this post is over 9 years old? And the OP has not been on the forum since 2010? Please do not resurrect old threads, especially to peddle a non-AutoIt solution.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
Melba23

ElijahWright,

And as in addition you only registered to advertise a payware solution, you can vanish. Bye!

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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

×