Delete file from C

System invokes the DOS command interpreter file from inside an executing C
program to execute a DOS command to delete the file.
To be located and executed, the program must be in the current directory or
in the directories whose path is given.


>> So the following code delete the file whose location is specified.
    #include<stdio.h>
    #include<dos.h>
    void main(void)
    {
      union REGS i,o;
      char fname[67];
      puts(“\nEnter file name: “);
      gets(fname);
      i.h.ah = 0×41;
      i.x.dx = fname;
      intdos(&i,&o);
      if(o.x.cflag == 0)
      printf(“\n%s File successfully deleted”,fname);
      else
      printf(“\n%s File could not be deleted”,fname);
    }

Comments

Popular Posts