DosDelete

From EDM2
Jump to: navigation, search

Removes a file name from a directory. The deleted file may be recoverable.

Syntax

DosDelete(pszFile)

Parameters

pszFile (PSZ) - input
Address of the name of the file to be deleted.

Return Code

ulrc (APIRET) - returns
DosDelete returns one of the following values:
  • 0 NO_ERROR
  • 2 ERROR_FILE_NOT_FOUND
  • 3 ERROR_PATH_NOT_FOUND
  • 5 ERROR_ACCESS_DENIED
  • 26 ERROR_NOT_DOS_DISK
  • 32 ERROR_SHARING_VIOLATION
  • 36 ERROR_SHARING_BUFFER_EXCEEDED
  • 87 ERROR_INVALID_PARAMETER
  • 206 ERROR_FILENAME_EXCED_RANGE

Remarks

Global file-name characters are not permitted in the name of the file to be deleted.

Read-only files cannot be deleted by DosDelete. To delete a read-only file, you must first issue DosSetFileInfo to change the file's read-only attribute to zero, then delete the file.

If a storage directory for the drive has been defined with the SET DELDIR command, the UNDELETE command may recover the deleted file.

DosDelete cannot be used to delete directories. Issue DosDeleteDir to delete a directory.

Example Code

This example creates and deletes a file named "TEST.DAT".

#define INCL_DOSFILEMGR          /* File Manager values */
#define INCL_DOSERRORS           /* DOS error values    */
#include <os2.h>
#include <stdio.h>

int main(void) {
   HFILE  hfFileHandle    = 0L;          /* File Handle */
   ULONG  ulAction        = 0;           /* Action taken */
   UCHAR  uchFileName[20] = "test.dat";  /* File path name */
   APIRET rc              = NO_ERROR;    /* Return code */

   /* Create the file test.dat */

   rc = DosOpen(uchFileName,
                &hfFileHandle,
                &ulAction,
                10L,
                FILE_NORMAL,
                FILE_CREATE,
                OPEN_ACCESS_WRITEONLY | OPEN_SHARE_DENYNONE,
                0L);
   if (rc != NO_ERROR) {
      printf("DosOpen error: return code = %u\n", rc);
      return 1;
   } else {
     printf("DosOpen:   File created = %s\n", uchFileName);
   } /* endif */

   rc = DosClose(hfFileHandle);        /* Close the file */
   if (rc != NO_ERROR) {
     printf("DosClose error: return code = %u\n", rc);
     return 1;
   } /* endif */

   /* Delete file "test.dat" from current directory */

   rc = DosDelete(uchFileName);
   if(rc != NO_ERROR) {
     printf("DosDelete error: return code = %u\n", rc);
     return 1;
   } else {
     printf("DosDelete: File deleted = %s\n", uchFileName);
   } /* endif */

   return NO_ERROR;
}

Related Functions