Deleting a File or Directory

Once you are finished with a file, close the file handle by using the CloseHandle function. CloseHandle is a generic function that closes a variety of handles, including the handle to a file. If you leave a file open when your application terminates, Windows CE automatically closes the file.

    To close and delete a file

  1. Close the file with a call to CloseHandle.
  2. Delete the file with a call to the DeleteFile function.

    Windows CE cannot delete a file that has an open handle.

Call the RemoveDirectory function, with the full path name of the directory in the lpPathName parameter, to delete a directory. You must delete all of the files in the directory before calling RemoveDirectory.