C++ ImplementationThe C++ implementation is composed of the source files listed below.
Directory operations are the only new C++ and WIN32 coding concepts introduced in these programs. To create an output directory in the CSVSourceConverter's processFile method, we use the _mkdir function. iReturn = _mkdir(cOutputDirectory); To read an input directory in the XMLToCSV main program, we use the FindFirstFile library routine, followed by successive calls to FindNextFile. FindFirstFile returns a File HANDLE and a WIN32_FIND_DATA structure from which we can retrieve the file name . FindNextFile returns us the next HANDLE and its WIN32_FIND_DATA structure. Here are the relevant lines from the code. HANDLE hFind; WIN32_FIND_DATA FindFileData; ... // For FindFirstFile, append wildcards if ( strcmp( &(cInputDirectoryFindPath[i-3]),"*.*") != 0) { strcat(cInputDirectoryFindPath,"*.*"); } // Open input directory // Get first file from input directory hFind = FindFirstFile(cInputDirectoryFindPath, &FindFileData); if (hFind == INVALID_HANDLE_VALUE) { throw cInputDirectoryOpenError; } // DO for all files in input directory do { // Skip directory file paths if (FindFileData.cFileName[0] == '.') { continue; } // Build input file name memset(cInputFileName,0,MAX_PATH_LENGTH); strcpy(cInputFileName,cInputDirectoryName); strcat(cInputFileName,FindFileData.cFileName); ... Load, parse, and process the document } while (FindNextFile(hFind, &FindFileData) == TRUE); // ENDDO // Close the input directory FindClose(hFind); |