Write a program to Delete a specified file using Interrupt 21h.

 # include <stdio.h>
 # include <conio.h>
 # include   <dos.h>

 constint DeleteFile(constchar*);

 int main( )
 {
    char* File=NULL;
    clrscr( );

    printf(" Enter the File Path and Name to delete = ");
    scanf("%s",File);

    if(DeleteFile(File))
       printf("\n Error : Unable to delete the file.");
    else
       printf("\n The File is deleted sucessfully.");

    getch( );
    return 0;
 }

 /*DeleteFile( ) */

constint DeleteFile(constchar* File)
 {
    union REGS InReg;
    union REGS OutReg;

    InReg.h.ah=0x41;
    InReg.x.dx=FP_OFF(File);

    int86(0x21,&InReg,&OutReg);

    return OutReg.x.cflag;
 }

Post a Comment

0 Comments