DUDOS.CPP

 #include<iostream.h>
#include<conio.h>
#include<fstream.h>
#include<dos.h>
#include<process.h>
#include<direct.h>
#include<string.h>
#include<stdio.h>
#define CF 1
void main()
{
clrscr();
char directory[80];
char str[10],ch,fn1[67],fn2[67],fn3[67],DIRNAME[67];
int x=0;int stat,done;
do
{
lb:
fflush(stdin);
getcwd(directory,80);
cout<<endl<<directory<<"\>";
cin>>str;
if(strcmpi(str,'\0')==0)
goto lb;
else if(strcmpi(str,"exit")==0)
{
exit(0);
}
else if(strcmpi(str,"ver")==0)
cout<<"\nDOS DUPLICATED VERSION\n";
else if(strcmpi(str,"time")==0)
{
struct time T;
gettime(&T);
cout<<"\nTIME::"<<(int)T.ti_hour<<":"<<(int)T.ti_min<<":"<<(int)T.ti_sec<<endl;
}
else if(strcmpi(str,"date")==0)
{
struct date D;
getdate(&D);
cout<<"\nDATE::"<<(int)D.da_day<<"/"<<(int)D.da_mon<<"/"<<(int)D.da_year<<endl;
}
else if(strcmpi(str,"edit")==0)
{
cin>>fn1;
ofstream f;
f.open(fn1,ios::app);
while((ch=getc(stdin))!=EOF)
{ f.put(ch);}
f.close();
}
else if(strcmpi(str,"type")==0)
{
cin>>fn1;
ifstream f(fn1);
if(f.fail())
cout<<"\nFile not found";
else
{
while(f)
{
if(f)
{
f.get(ch);
cout<<ch;
}
}
f.close();
}
}
else if(strcmpi(str,"ren")==0)
{
cin>>fn1;
cin>>fn2;
ifstream f1(fn1);
ifstream f2(fn2);
if(f1.fail()||f2.fail())
{ cout<<"\nEither of these files do not exist";goto lb;}
else
{
rename(fn1,fn2);
cout<<"\nRenamed";
}
}
else if(strcmpi(str,"del")==0)
{
cin>>fn1;
ifstream f1(fn1);
if(f1.fail())
cout<<"\nFile does not exist";
else
{
remove(fn1);
cout<<"\nFile deleted";
}
}
else if(strcmpi(str,"copy")==0)
{
cin>>fn1;
cin>>fn2;
ifstream f1(fn1);
if(f1.fail())
{ cout<<"File "<<fn1<<" does not exist";goto lb;}
ofstream f2(fn2);
f1.seekg(0);
while(f1)
{
f1.get(ch);
f2.put(ch);
}
f1.close();
f2.close();
cout<<"\nFile copied onto another";
}
else if(strcmpi(str,"scan")==0)
{
cin>>fn1;
ifstream f(fn1);
if(f.fail())
{ cout<<"\nFile "<<fn1<<" does not exist";goto lb;}
if(f.bad())
cout<<"\nFatal file or file not found";
else if(f.good())
cout<<"\nNo errors found";
f.close();
}
else if(strcmpi(str,"concat")==0)
{
cin>>fn1;
cin>>fn2;
cin>>fn3;
int e1,e2;
ifstream f1(fn1,ios::in);
if(f1.fail())
{ cout<<"File "<<fn1<<" does not exist";goto lb;}
ofstream f2(fn2,ios::app);
while(f1)
{
f1.read((char *) &ch,sizeof(ch));
f2.write((char *) &ch,sizeof(ch));;
}
f1.close();
f2.close();
ofstream f3(fn3,ios::app);
ifstream f4(fn2,ios::in);
while(f4)
{
f4.read((char *) &ch,sizeof(ch));
f3.write((char *) &ch,sizeof(ch));;
}
f4.close();
f3.close();
}
else if(strcmpi(str,"md")==0)
{
cin>>DIRNAME;
stat = mkdir(DIRNAME);
if(!stat)
cout<<"\nDirectory created\n";
}
else if(strcmpi(str,"rd")==0)
{
cin>>DIRNAME;
stat = rmdir(DIRNAME);
if (!stat)
cout<<"\nDirectory deleted\n";
else
cout<<"\nDirectory not found\n";
}
else if(strcmpi(str,"cd")==0)
{
struct REGPACK reg;
cin>>directory;
b:
reg.r_ax = 0x3B << 8;
reg.r_dx = FP_OFF(directory);
reg.r_ds = FP_SEG(directory);
intr(0x21, &reg);
if (reg.r_flags & CF)
cout<<"Directory change failed\n";
}
else if(strcmpi(str,"cd\")==0)
{
strcpy(directory,"\");
goto b;
}
else if(strcmpi(str,"cd..")==0)
{
strcpy(directory,"..");
goto b;
}
else if(strcmpi(str,"cls")==0)
clrscr();
else if(strcmpi(str,"dir")==0)
{
cin>>fn1;
struct ffblk ffblk;
struct find_t ff;
done = findfirst(fn1,&ffblk,0);
if(done!=0)
cout<<"\nFile(s) not found";
else
{
cout<<"\nShows only files\n";
while (!done)
{
cout<<"\n"<<ffblk.ff_name;
done = findnext(&ffblk);
}
}
}
}while(x<20);
}

Project Homepage: