Q:

deleting file in ntfs using c

How can I delete a file on an ntfs drive? i tried deletefile and remove, but neither worked. Any suggestions?
do { 
  char* nPtr = new char [lstrlen( data.cFileName ) + 1]; 

  for( int i = 0; i < lstrlen( data.cFileName ); i++ ) 
    nPtr[i] = char( data.cFileName[i] ); 

  nPtr[lstrlen( data.cFileName )] = '\0'; 

  if(!strcmp(nPtr , fn)) 
    remove(nPtr); 

  cout << nPtr << endl; 
}

thanks arefin

A:

The call to DeleteFile() does work and in your case it did work.
DeleteFile() is contracted to delete the file you specify, if it can be deleted.  If the file could be deleted, then it will be. If the file could not be deleted then it will not be.
If DeleteFile() returns false, what the documentation refers to as failure, then the file was not deleted, for a good reason.  You can call GetLastError() to find out why the file was not deleted.

A:

"didn't work" can happen because mistake in parameter (path specified not correctly) or because you don't have  permissions to delete the file or because the file is in use. Resolutions are different for these causes. You can check what the actual problem is by checking whether DeleteFile() returns false and then calling GetLastError() function to get the error code. 
Error codes: 
2 - file not found
  3 - path not found
  5 - access denied
  87 - invalid parameter

