Hi all,
Following is the function which takes the path & the file name to be checked.
When there is 1 file in the path it works fine but when there are more than one file in the path after the 1st file is processed successfully for the 2nd file the path variable is coming as path/1st file_name2nd file_name whereas it should come as path/1st file_name & path/2nd file_name.
So in this case i cant process multiple files.
Dont know where im going wrong, need you people to point out what i am doing wrong here.
Code:
int ValidateFile(char *cFnm, char *rawPath)
{
FILE* f_read;
int c = 0, i = 0;
char buf[MAX_LINE_LEN+1];
int lenPerline = 0;
int numOfComma = 0;
int lineNo = 0, numOfErr = 0;
strcat(rawPath,cFnm);
f_read = fopen(rawPath, "r");
if (!f_read) {
perror("Failed opening file for reading:");
LogFile("ERROR : Failed opening file for reading:",rawPath,-1,0);
return -1;
}
LogFile("Successful opening file :",rawPath,-1,0);
while (fgets(buf, MAX_LINE_LEN+1, f_read)){
if (lineNo == 0){
lenPerline = strlen(buf);
for (i = 0; i < lenPerline; i++){
if (buf[i] == ',') {
numOfComma++;
}
}
if (numOfComma == 8){
LogFile("File is Valid!!, proceed to data formatting process....","",-1,0);
lineNo++;
}else{
/*Generate error file*/
LogFile("ERROR : Number of colunms are not tally in this file....","",-1,0);
fclose(f_read);
return -1;
}
} else
{
LogFile("Loading data to DB...","",-1,0);
if (LoadDataToDb(buf,cFnm) == -1){
return -1;
}
lineNo++;
}
}
if (CheckRecord(cFnm) == -1){
return -1;
}
if (FormatFile(cFnm) == -1){
return -1;
}
numOfErr = ReportFile(cFnm);
if (numOfErr > 0){
if (ErrorFile(cFnm) == -1){
return -1;
}
}else
{
if (numOfErr == -1){
return -1;
}else {
LogFile("No error detected. No file to be generated..","",-1,0);
}
}
LogFile("Moving File to done directory..","",-1,0);
MoveFileToDir(1, cFnm);
numOfComma = 0;
lineNo = 0;
fclose(f_read);
return 0;
}
Thanks