1

Whats wrong about this?

if((
::DeleteFile( L"IO.res"))== NULL)
MessageBox(NULL,L"Error",L"OK",MB_OK);

I have the IO.res file in the same directory, but the program cant delete it. With the integrated File manager I can delete. I use EVC4.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Luther
  • 155
  • 1
  • 2
  • 7
  • 1
    What is the value of `GetLastError()` immediately after `DeleteFile` returns? Also, you should be comparing the return value with 0, not `NULL` -- it returns `BOOL`, not a pointer type. – Adam Rosenfield May 11 '12 at 21:22
  • I dont know what is the return value of the GetLastError, because its dont want working: if(( ::DeleteFile( L"IO.res"))== 0) DWORD error; error=GetLastError(); MessageBox(NULL,error,L"OK",MB_OK); – Luther May 11 '12 at 21:42
  • I fixed the NULL to 0. But the IO.res still exist. – Luther May 11 '12 at 21:44
  • Try this instead to get the error: `if(DeleteFile(L"IO.res") == 0) { wchar_t buffer[256]; _snwprintf(buffer, 256, "Delete file failed with error %d", GetLastError()); MessageBox(NULL, buffer, L"Error", MB_OK); }` – Adam Rosenfield May 11 '12 at 21:55
  • error C2664: '_snwprintf' : cannot convert parameter 3 from 'char [33]' to 'const unsigned short *' – Luther May 11 '12 at 22:19
  • 1
    Y'know, I try to be helpful, but I'm not going to handhold you through everything. I made a slight mistake in that code fragment, but you really ought to be able to fix that yourself. – Adam Rosenfield May 11 '12 at 22:31
  • Ok, fixed. The GetLastError() value is ERROR_FILE_NOT_FOUND – Luther May 12 '12 at 10:45

1 Answers1

4

Windows CE doesn't have any concept of a "current" or "working" directory. You must provide a fully qualified path to the file you want to delete.

ctacke
  • 66,480
  • 18
  • 94
  • 155
  • I tried with specified directory but the problem is the same. – Luther May 11 '12 at 22:21
  • The we need the *exact* code you ran and the result from GetLastError. Using the debugger you should be able to get the value without printing it out. Use the Locals window. – ctacke May 12 '12 at 02:29
  • Solved! The problem is really to need specify the foldername! First time Im wrong when I give the file path. Now its working! Thanks a lot to ctacke and Adam Rosenfield, and sorry about the newbie questions. – Luther May 12 '12 at 11:42