Hi Everybody, I am little new to C++ program. I want to write a program which could be able to read data from files which is in a folder. Following my program could be able to read all data in files. Now say each files has 10 lines of data. My program should read each files first line data and put it into a folder in a file, name result1, then it should read second data of each files and put it into the folder with file name result2. and so on................ This is my code, Code: [B]int printFiles(char * dirname) { char* POV; DIR* dirp; string buff; struct dirent* dp; [COLOR=Navy]system("mkdir POV"); [/COLOR] ofstream output("test.pov"); [COLOR=Green]dirp = opendir(dirname);[/COLOR] if ( !dirp ) { cout << "Error: failure opening directory" << endl; exit(1); } errno = 0; [COLOR=Green]while ( dp = readdir(dirp) ) {[/COLOR] if(dp !=NULL) { if(strstr(dp->d_name, ".dat")) { ifstream input(dp->d_name); while( getline(input, buff) ) { cout << buff << endl; output<< buff << endl; } } } if ( errno ) { cout << "Error: readdir() failure!" << endl; exit(1); } } closedir( dirp ); }[/B] Here I dont know how to read each files data and put them into corresponding files. Pls help me. Regards, Sitha.