Skip to content

Instantly share code, notes, and snippets.

@amalaugustinejose
Created January 26, 2017 14:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amalaugustinejose/22dd0f6ed40e411493cd6792c81661f7 to your computer and use it in GitHub Desktop.
Save amalaugustinejose/22dd0f6ed40e411493cd6792c81661f7 to your computer and use it in GitHub Desktop.
C program to create, delete and rename a file.
#include<stdio.h>
#include<process.h>
#include<dos.h>
void main() {
char loc[50], filename[50], oldname[50], ch;
int opr, gate = 1;
long int attr;
union REGS inreg, outreg;
clrscr();
do {
printf("\nSelect Operation\n");
printf("\n\t1 - Create a file\n");
printf("\n\t2 - Delete a file\n");
printf("\n\t3 - Rename a file\n");
scanf("%i", &opr);
switch(opr) {
case 1:
printf("\nCreate a file\n");
printf("\nEnter location : ");
scanf("%s", loc);
inreg.h.ah = 0x3B;
inreg.x.dx = (int)loc;
int86(0x21, &inreg, &outreg);
printf("\nEnter file name : ");
scanf("%s", filename);
printf("\nEnter file attributes : ");
scanf("%i", &attr);
inreg.h.ah = 0x3C;
inreg.x.dx = (int)filename;
inreg.x.cx = (long)attr;
int86(0x21, &inreg, &outreg);
if (outreg.x.cflag == 0)
printf("\nFile Created\n");
else
printf("\nError Creating file\n");
break;
case 2:
printf("\nDelete a file\n");
printf("\nEnter location : ");
scanf("%s", loc);
inreg.h.ah = 0x3B;
inreg.x.dx = (int)loc;
int86(0x21, &inreg, &outreg);
printf("\nEnter file name : ");
scanf("%s", filename);
inreg.h.ah = 0x41;
inreg.x.dx = (int)filename;
int86(0x21, &inreg, &outreg);
if (outreg.x.cflag == 0)
printf("\nFile Deleted\n");
else
printf("\nError deleting file\n");
break;
case 3:
printf("\nRename a file\n");
printf("\nEnter location : ");
fflush(stdin);
scanf("%s", loc);
fflush(stdin);
inreg.h.ah = 0x3B;
inreg.x.dx = (int)loc;
int86(0x21, &inreg, &outreg);
printf("\nEnter old name : ");
scanf("%c", ch);
printf("%s", oldname);
fflush(stdin);
printf("\nEnter new name : ");
scanf("%s", filename);
inreg.h.ah = 0x56;
inreg.x.dx = (int)oldname;
inreg.x.di = (int)filename;
int86(0x21, &inreg, &outreg);
if (outreg.x.cflag == 0)
printf("\nFile Renamed\n");
else
printf("\nError renaming file\n");
break;
default:
printf("\nInvalid Operation\n");
}
printf("\nDo you want to continue 1 / 0 : ");
scanf("%i", &gate);
}while(gate);
getch();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment