Created
January 26, 2017 14:48
-
-
Save amalaugustinejose/22dd0f6ed40e411493cd6792c81661f7 to your computer and use it in GitHub Desktop.
C program to create, delete and rename a file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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