Deleting the temporary files, VC++ 6.0


We have an correspondence application developed in VC++ and using mail merge technology which sends emails to the customers in word documents. Here is my code which is used to delete the temp files once the email is sent , but the "retD returns 0", which means it failed to delete the file and the file is still haging in the temp folder.

I used the GetLastError() function and it returns 2, which means "File Not found Error"
but I put check "fileN" , it does shows the exact path and the document name which need to be deleted.

Can you one point me in right direction as to how to delete the file?


// delete temporary files
BOOL retD;
for ( i = 0; i < mergedFiles.GetSize(); i++ ) 
	CString fileN = mergedFiles[i];
	//retD = DeleteFile (mergedFiles[i]);
	retD = DeleteFile(fileN);
mergedFiles is an CStringArray

Open in new window

Who is Participating?
rbhargawConnect With a Mentor FounderAuthor Commented:
I flushed out the memory of all COM components and then tried to delete and that worked.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.