Jump to content

DosForceDelete: Difference between revisions

From EDM2
Created page with "==Description== Removes a file name from a directory. The deleted file is not recoverable. ==Syntax== <PRE> #define INCL_DOSFILEMGR #include <os2.h> PSZ pszFile; /* ..."
 
Ak120 (talk | contribs)
mNo edit summary
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
==Description==
Removes a file name from a directory. The deleted file is not recoverable.
Removes a file name from a directory. The deleted file is not recoverable.


==Syntax==
==Syntax==
<PRE>
DosForceDelete (pszFile)
#define INCL_DOSFILEMGR
#include <os2.h>


PSZ       pszFile;  /*  Address of the name of the file to be deleted. */
==Parameters==
APIRET    ulrc;    /*  Return Code. */
;pszFile (PSZ) - input : Address of the name of the file to be deleted.


ulrc = DosForceDelete(pszFile);
</PRE>
==Parameters==
;  pszFile (PSZ) - input : Address of the name of the file to be deleted.
==Return Code==
==Return Code==
ulrc (APIRET) - returns
;ulrc (APIRET) - returns:DosForceDelete returns one of the following values:
 
*0 NO_ERROR
DosForceDelete returns one of the following values:
*2 ERROR_FILE_NOT_FOUND
 
*3 ERROR_PATH_NOT_FOUND
* 0   NO_ERROR  
*5 ERROR_ACCESS_DENIED
* 2       ERROR_FILE_NOT_FOUND  
*26 ERROR_NOT_DOS_DISK
* 3       ERROR_PATH_NOT_FOUND  
*32 ERROR_SHARING_VIOLATION
* 5       ERROR_ACCESS_DENIED  
*36 ERROR_SHARING_BUFFER_EXCEEDED
* 26       ERROR_NOT_DOS_DISK  
*87 ERROR_INVALID_PARAMETER
* 32       ERROR_SHARING_VIOLATION  
*123 ERROR_INVALID_NAME
* 36       ERROR_SHARING_BUFFER_EXCEEDED  
*206 ERROR_FILENAME_EXCED_RANGE
* 87       ERROR_INVALID_PARAMETER  
* 123       ERROR_INVALID_NAME  
* 206       ERROR_FILENAME_EXCED_RANGE


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


Read-only files cannot be deleted by DosForceDelete. 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.
Read-only files cannot be deleted by DosForceDelete. 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.


The deleted file cannot be recovered with the UNDELETE command. You may want to issue DosForceDelete to delete a temporary file that you would not want to recover.
The deleted file cannot be recovered with the UNDELETE command. You may want to issue DosForceDelete to delete a temporary file that you would not want to recover.


DosForceDelete cannot be used to delete directories. Issue DosDeleteDir to delete a directory.  
DosForceDelete cannot be used to delete directories. Issue [[DosDeleteDir]] to delete a directory.


==Example Code==
==Example Code==
This example creates a read-only file named "DOSFDEL.DAT", it then changes the file attributes. DosForceDelete is used to delete this file so it is not possible to restore it using UNDELETE.
This example creates a read-only file named "DOSFDEL.DAT", it then changes the file attributes. DosForceDelete is used to delete this file so it is not possible to restore it using UNDELETE.
<PRE>
<code>
 
  #define INCL_DOSFILEMGR  /* File Manager values */
  #define INCL_DOSFILEMGR  /* File Manager values */
  #define INCL_DOSERRORS    /* DOS error values    */
  #define INCL_DOSERRORS    /* DOS error values    */
  #include <os2.h>
  #include <os2.h>
  #include <stdio.h>
  #include <stdio.h>
 
  int main(VOID) {
  int main(VOID) {
 
  UCHAR      uchFileName[]  = "DOSFDEL.DAT";  /* File we want to delete    */
  UCHAR      uchFileName[]  = "DOSFDEL.DAT";  /* File we want to delete    */
  HFILE      fhDelFile      = 0;              /* File handle from DosOpen  */
  HFILE      fhDelFile      = 0;              /* File handle from DosOpen  */
  FILESTATUS3 fsts3FileInfo  = {{0}};  /* Information associated with file   */
  FILESTATUS3 fsts3FileInfo  = <nowiki>{{0}};  /* Information associated with file */</nowiki>
  ULONG      ulBufferSize    = sizeof(FILESTATUS3); /* File info buffer size */
  ULONG      ulBufferSize    = sizeof(FILESTATUS3); /* File info buffer size */
  ULONG      ulOpenAction    = 0;                /* Action taken by DosOpen */
  ULONG      ulOpenAction    = 0;                /* Action taken by DosOpen */
  APIRET      rc              = NO_ERROR;          /* Return code            */
  APIRET      rc              = NO_ERROR;          /* Return code            */
 
                 /* Create a read-only file */
                 /* Create a read-only file */
 
   rc = DosOpen(uchFileName, &fhDelFile,
   rc = DosOpen(uchFileName, &fhDelFile,
               &ulOpenAction, 10L, FILE_READONLY,
               &ulOpenAction, 10L, FILE_READONLY,
Line 68: Line 55:
     printf("DosOpen error: return code = %u\n", rc);
     printf("DosOpen error: return code = %u\n", rc);
     return 1;      }
     return 1;      }
 
   rc = DosQueryFileInfo(fhDelFile, FIL_STANDARD,
   rc = DosQueryFileInfo(fhDelFile, FIL_STANDARD,
                         &fsts3FileInfo, ulBufferSize);  /* Get standard info */
                         &fsts3FileInfo, ulBufferSize);  /* Get standard info */
Line 75: Line 62:
       return 1;
       return 1;
   } else { printf("File %s created read-only.\n",uchFileName); }
   } else { printf("File %s created read-only.\n",uchFileName); }
 
     fsts3FileInfo.attrFile  = FILE_NORMAL;
     fsts3FileInfo.attrFile  = FILE_NORMAL;
     rc = DosSetFileInfo(fhDelFile, FIL_STANDARD,
     rc = DosSetFileInfo(fhDelFile, FIL_STANDARD,
Line 83: Line 70:
         return 1;
         return 1;
     }
     }
 
     rc = DosClose(fhDelFile);
     rc = DosClose(fhDelFile);
     /* should check (rc != NO_ERROR) here... */
     /* should check (rc != NO_ERROR) here... */
 
           /* Delete the file */
           /* Delete the file */
 
     rc = DosForceDelete(uchFileName);
     rc = DosForceDelete(uchFileName);
     if (rc != NO_ERROR) {
     if (rc != NO_ERROR) {
Line 96: Line 83:
         printf("File %s has been deleted.\n",uchFileName);
         printf("File %s has been deleted.\n",uchFileName);
     } /* endif */
     } /* endif */
 
   return NO_ERROR;
   return NO_ERROR;
}
}
</code>


</PRE>
==Related Functions==
==Related Functions==
* [[OS2 API:CPI:DosDelete|DosDelete]]
*[[DosDelete]]
* [[OS2 API:CPI:DosDeleteDir|DosDeleteDir]]
*[[DosDeleteDir]]
* [[OS2 API:CPI:DosSetFileInfo|DosSetFileInfo]]
*[[DosSetFileInfo]]
 


[[Category:The OS/2 API Project]]
[[Category:Dos]]

Latest revision as of 03:26, 13 February 2019

Removes a file name from a directory. The deleted file is not recoverable.

Syntax

DosForceDelete (pszFile)

Parameters

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

Return Code

ulrc (APIRET) - returns
DosForceDelete 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
  • 123 ERROR_INVALID_NAME
  • 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 DosForceDelete. 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.

The deleted file cannot be recovered with the UNDELETE command. You may want to issue DosForceDelete to delete a temporary file that you would not want to recover.

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

Example Code

This example creates a read-only file named "DOSFDEL.DAT", it then changes the file attributes. DosForceDelete is used to delete this file so it is not possible to restore it using UNDELETE.

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

int main(VOID) {

UCHAR       uchFileName[]   = "DOSFDEL.DAT";   /* File we want to delete    */
HFILE       fhDelFile       = 0;               /* File handle from DosOpen  */
FILESTATUS3 fsts3FileInfo   = {{0}};  /* Information associated with file */
ULONG       ulBufferSize    = sizeof(FILESTATUS3); /* File info buffer size */
ULONG       ulOpenAction    = 0;                 /* Action taken by DosOpen */
APIRET      rc              = NO_ERROR;          /* Return code             */

                /* Create a read-only file */

 rc = DosOpen(uchFileName, &fhDelFile,
              &ulOpenAction, 10L, FILE_READONLY,
              OPEN_ACTION_CREATE_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS,
              OPEN_ACCESS_READWRITE | OPEN_SHARE_DENYNONE, 0L);
 if (rc != NO_ERROR) {
    printf("DosOpen error: return code = %u\n", rc);
    return 1;       }

 rc = DosQueryFileInfo(fhDelFile, FIL_STANDARD,
                       &fsts3FileInfo, ulBufferSize);  /* Get standard info */
 if (rc != NO_ERROR) {
     printf("DosQueryFileInfo error: return code = %u\n", rc);
     return 1;
 } else { printf("File %s created read-only.\n",uchFileName); }

   fsts3FileInfo.attrFile  = FILE_NORMAL;
   rc = DosSetFileInfo(fhDelFile, FIL_STANDARD,
                       &fsts3FileInfo, ulBufferSize);
   if (rc != NO_ERROR) {
       printf("DosSetFileInfo error: return code = %u\n", rc);
       return 1;
   }

   rc = DosClose(fhDelFile);
   /* should check (rc != NO_ERROR) here... */

          /* Delete the file */

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

  return NO_ERROR;
}

Related Functions