// ================================================ ========================================
// Title:
// VCF file Decomposition
// Author:
// Norains
// Date:
// Saturday 4-October-2008
// Environment:
// None
// ================================================ ========================================
Somehow, suo aik750 never got up again, so I had to buy a Nokia 5320. Fortunately, some of the contacts in Sony Ericsson k750 were found in PC's play-in mobile phone software, but I did not expect that play-in mobile phones would export all the contacts to a file, my 5320 pairs can only recognize one contact person for the same file. However, I wrote a program to extract contacts from the same file and save them as files of the same name.
The path is fixed because it is simple to extract and convenient to yourself. If you want to use this code, you can change the path to the corresponding file. Of course, it is best to make a pop-up dialog box and select a file ~
The Code is as follows;
// Vcardconvert. cpp: defines the entry point for the application.
//
# Include "stdafx. H"
# Include "string"
# Include "vector"
# Include "map"
# Define str_begin_flag "begin: vCard"
# Define str_end_flag "end: vCard"
# Define str_name_flag ";"
# Define str_file_read "H: // phone book. VCF"
# Define str_save_folder "H: // phone book //"
Int apientry winmain (hinstance,
Hinstance hprevinstance,
Lpstr lpcmdline,
Int ncmdshow)
{
// Todo: Place code here.
Handle hfileread = createfile (str_file_read, generic_read, null, null, open_existing, file_attribute_normal, null );
If (hfileread = invalid_handle_value)
{
Return 0x01;
}
// The read buffer
STD: vector <char> vtbuf (getfilesize (hfileread, null), 0 );
// Read the file
DWORD dwread = 0;
Readfile (hfileread, & vtbuf [0], vtbuf. Size (), & dwread, null );
If (dwread = 0)
{
Return 0x02;
}
// The buffer for finding
STD: String strbuf (vtbuf. Begin (), vtbuf. End ());
STD: Map <STD: String, STD: String> mpwrite;
// STD: vector <STD: String> vtstore;
// Store the content
STD: String: size_type posbegin = strbuf. Find (str_begin_flag, 0 );
STD: String: size_type posend = 0;
While (posbegin! = STD: String: NPOs)
{
Posend = strbuf. Find (str_end_flag, posbegin );
If (posend = STD: String: NPOs)
{
Break;
}
STD: String: size_type posnamebegin = strbuf. Find (str_name_flag, posbegin );
STD: String: size_type posnameend = strbuf. Find (str_name_flag, posnamebegin + 1 );
If (posnamebegin! = STD: String: NPOs & posnameend! = STD: String: NPOs)
{
Mpwrite. insert (STD: make_pair (STD: string (strbuf. Begin () + posnamebegin + 1, strbuf. Begin () + posnameend ),
STD: string (strbuf. Begin () + posbegin, strbuf. Begin () + posend + strlen (str_end_flag ))));
}
Posbegin = strbuf. Find (str_begin_flag, posend );
// Vtstore. push_back (STD: string (strbuf. Begin () + posbegin, strbuf. Begin () + posend + strlen (str_end_flag )));
}
Closehandle (hfileread );
// Write the text
For (STD: Map <STD: String, STD: String >:: iterator iter = mpwrite. Begin (); iter! = Mpwrite. End (); ITER ++)
{
STD: String strfile = str_save_folder;
Strfile + = ITER-> first;
Strfile + = ". VCF ";
Handle hfilewrite = createfile (strfile. c_str (), generic_write, null, null, create_always, file_attribute_normal, null );
If (hfilewrite = invalid_handle_value)
{
Return 0x01;
}
DWORD dwwrite = 0;
Writefile (hfilewrite, ITER-> second. c_str (), ITER-> second. Size (), & dwwrite, null );
Closehandle (hfilewrite );
}
Return 0;
}