You are on page 1of 3

# include <string.

h>
# include <stdio.h>
# include <conio.h>
# include
<dos.h>
# include
<dir.h>
void FindFile(constchar* Path,constchar* FileName);
constint DeleteFile(constchar* File);
int main( )
{
int count;
int cur_drive=getdisk( );
int total_drives=setdisk(2);
char Drive[10]={"C:\\"};
char FileName[15]={NULL};
char CurrentDirectory[MAXPATH]={NULL};
clrscr( );
getcwd(CurrentDirectory,MAXPATH);
printf("Enter the File Name to delete: ");
scanf("%s",FileName);
printf("\nSearching....\n\n");
for(count=2;count<total_drives;count++)
{
setdisk(count);
if(count==getdisk( ))
{
Drive[0]=(65+count);
FindFile(Drive,FileName);
}
}
setdisk(cur_drive);
chdir(CurrentDirectory);
printf("\nPress any key to exit...");
getch( );
return 0;
}
/*************************************************************************/
//---------------------------- FindFile( ) ----------------------------//
/*************************************************************************/
void FindFile(const char* Path,const char* FileName)
{
struct find_t ffblk;
int flag;

char File[MAXPATH]={NULL};
chdir(Path);
strcpy(File,Path);
strcat(File,FileName);
flag=_dos_findfirst(File,_A_NORMAL,&ffblk);
if(!flag)
{
char Choice;
while(!flag)
{
printf("File Found:: %s%s\n",Path,ffblk.name);
printf("Do you want to delete it? (Y/N) : ");
Choice=getche( );
if(Choice=='Y' || Choice=='y')
{
char Temp[MAXPATH]={NULL};
strcpy(Temp,Path);
strcat(Temp,ffblk.name);
if(DeleteFile(Temp))
{
printf("Unable to delete the specified file.");
getch( );
}
}
printf("\n\n");
flag=_dos_findnext(&ffblk);
}
}
strcpy(File,Path);
strcat(File,"*.*");
flag=_dos_findfirst(File,FA_DIREC,&ffblk);
while(!flag)
{
if(strcmp(ffblk.name,".")!=0 && strcmp(ffblk.name,"..")!=0 &&
ffblk.attrib==FA_DIREC)
{
char Temp[MAXPATH]={NULL};
strcpy(Temp,Path);
strcat(Temp,ffblk.name);
strcat(Temp,"\\");
FindFile(Temp,FileName);
}

flag=_dos_findnext(&ffblk);
}
chdir(Path);
}
/*************************************************************************///-------------------------- DeleteFile( ) ---------------------------///********
*****************************************************************/constint Delet
eFile(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;
}

You might also like