Ok well i need help with my code, the idea is to make something like a DOS Console, the trick is we are not alowed to use dos functions.
Well this is what i have so far
#include <stdio.h>
#include <iostream.h>
#include <conio.h>
#include <string.h>
#include <dir.h>
#include <dos.h>
#include <errno.h>
#include <io.h>
#include <process.h>
#include <sys\stat.h>
void clear();
void chatt();
char directory();
void cdd();
void deletee();
void cdup();
void time();
void date();
void dir();
void create();
void copy();
void deleteee();
void watchatt();
void renamee();
void main()
{ char z,* texto;
int q,t,error;
q=0;
while(q==0)
{
directory();
error=1;
fflush(stdin);
gets(texto);
cout<<"";
t=strcmp(texto,"");
if(t==0)
error=0;
t=strcmp(texto,"erase");
if(t==0)
{ deletee();
error=0;
}
t=strcmp(texto,"exit");
if(t==0)
{ q++;
error=0;
}
t=strcmp(texto,"cd");
if(t==0)
{
cdd();
error=0;
}
t=strcmp(texto,"cd..");
if(t==0)
{ cdup();
error=0;
}
t=strcmp(texto,"attrib");
if(t==0)
{
watchatt();
error=0;
}
t=strcmp(texto,"dir");
if(t==0)
{
dir();
error=0;
}
t=strcmp(texto,"clear");
if(t==0)
{
clear();
error=0;
}
t=strcmp(texto,"chmod");
if(t==0)
{
chatt();
error=0;
}
t=strcmp(texto,"rename");
if(t==0)
{
renamee();
error=0;
}
t=strcmp(texto,"create");
if(t==0)
{
create();
error=0;
}
t=strcmp(texto,"date");
if(t==0)
{
date();
error=0;
}
t=strcmp(texto,"copy");
if(t==0)
{
copy();
error=0;
}
t=strcmp(texto,"time");
if(t==0)
{
time();
error=0;
}
t=strcmp(texto,"del");
if(t==0)
{
deleteee();
error=0;
}
if(error==1)
cout<<"El comando es invalido\n";
}
}
char directory()
{
char dire[128];
getcwd(dire, 128);
cout<<dire<<":";
return 0;
}
void cdd()
{
char *route;
cin>>route;
chdir(route);
}
void cdup()
{
chdir("..");
}
void deletee()
{
int x,y;
for(x=0;x<=80;x++)
for(y=0;y<=100;y++)
{ gotoxy(x,y);
printf(" ");
gotoxy(1,1);
}
}
void dir()
{
struct ffblk ffblk;
int done;
cout<<"Directory list\n";
done = findfirst("*.*",&ffblk,0);
while (!done)
{
cout<< ffblk.ff_name<<endl;
done = findnext(&ffblk);
}
}
void clear()
{
clrscr();
}
void create()
{
char *newdir;
cin>>newdir;
mkdir(newdir);
}
void copy()
{
char src[64];
char dest[64];
cout<<"File to copy: ";
gets(src);
cout<<"Destination: ";
gets(dest);
}
void deleteee()
{
}
void watchatt()
{
unsigned attrib;
char fileatt [64];
cout<<"Name of the file";
cin>>fileatt;
_dos_getfileattr(fileatt,&attrib);
if(attrib & _A_RDONLY)
cout<<"File is read only"<<endl;
if(attrib & _A_HIDDEN)
cout<<"File is hidden"<<endl;
if(attrib & _A_SYSTEM)
cout<<"File is from the system"<<endl;
if(attrib & _A_VOLID)
cout<<"File is a volume label"<<endl;
if(attrib & _A_SUBDIR)
cout<<"File is a directory"<<endl;
if(attrib & _A_ARCH)
cout<<"File is an archive"<<endl;
}
void chatt()
{
char filename1[64];
char fileop, op;
struct stat stbuf;
int amode;
cout<<"Name of file: ";
cin>>filename1;
if(stat(filename1,&stbuf)!=0)
{
cout<<"Unable to get file information"<<endl;
exit(1);
}
if(stbuf.st_mode & S_IWRITE)
{
cout<<"File is a read and write"<<endl<<"Would you like to change it? ";
cin>>fileop;
switch(fileop)
{
case 'Y':
cout<<"Choose your option: ";
cout<<"\n 1. Read Only";
cout<<"\n 2, Exit";
cin>>op;
switch(op)
{
case '1':
amode=S_IREAD;
break;
default:
cout<<"Going out";
}
default: "Going out";
}
}
if(stbuf.st_mode & S_IREAD)
{
cout<<"File is a read only"<<endl<<"Would you like to change it? ";
cin>>fileop;
switch(fileop)
{
case 'Y':
cout<<"Choose your option: ";
cout<<"\n 1. Read and Write";
cout<<"\n 2, Exit";
cout<<endl;
cin>>op;
switch(op)
{
case '1':
amode=S_IWRITE;
break;
default:
cout<<"Going out";
}
default: "Going out";
}
}
if(chmod(filename1,amode) != 0 )
{
cout<<"Unable to change file mode";
}
}
void time()
{
struct time t;
int newtime[4];
int cht;
char y_n;
gettime(&t);
int j=0;
newtime[0]=t.ti_hour;
newtime[1]=t.ti_min;
newtime[2]=t.ti_sec;
newtime[3]=t.ti_hund;
cout<<"The current time is: ";
for (int i=0;i<4;i++)
{
cout<<newtime[i]<<":";
}
cout<<"\n Would you like to modify the time?";
cout<<"\n Yes = y";
cout<<"\n No = n";
cin>>y_n;
if(y_n=='y')
{
while(cht!=27)
{
cht=getch();
if(cht==80)
{
newtime[j] =t.ti_hour--;
settime(&t);
}
if(cht==72)
{
newtime[j]=t.ti_hour++;
settime(&t);
}
if(cht==77)
{
j++;
}
if(cht==80)
{
newtime[j] =t.ti_min--;
settime(&t);
}
if(cht==72)
{
newtime[j]=t.ti_min++;
settime(&t);
}
if(cht==80)
{
newtime[j] =t.ti_sec--;
settime(&t);
}
if(cht==72)
{
newtime[j]=t.ti_sec++;
settime(&t);
}
if(cht==80)
{
newtime[j] =t.ti_hund--;
settime(&t);
}
if(cht==72)
{
newtime[j]=t.ti_hund++;
settime(&t);
}
if(cht==77&&j==3)
{
cout<<"You can only go back now!";
}
if(cht==75)
{
j--;
}
if(cht==75&&j==0)
{
cout<<"You can only move forward!";
}
if(cht==13)
{
cout<<"The current time is: ";
for (int i=0;i<4;i++)
{
cout<<newtime[i]<<":";
}
cht=27;
}
}
}
cout<<endl;
}
void date()
{
struct date d;
struct date d2;
int newdate[3];
int chd;
char y_n;
getdate(&d2);
getdate(&d);
int j=0;
newdate[0]=d.da_day;
newdate[1]=d.da_mon;
newdate[2]=d.da_year;
cout<<"The current time is: ";
for(int i=0;i<3;i++)
{
cout<<newdate[i]<<".";
}
cout<<"\n Would you like to modify the date?";
cout<<"\n Yes = y";
cout<<"\n No = n";
cin>>y_n;
if(y_n=='y')
{
while(chd!=27)
{
chd=getch();
if(chd==80)
{
newdate[j] =d.da_day--;
setdate(&d);
}
if(chd==72)
{
newdate[j]=d.da_day++;
setdate(&d);
}
if(chd==77)
{
j++;
}
if(chd==80)
{
newdate[j] =d.da_mon--;
setdate(&d);
}
if(chd==72)
{
newdate[j]=d.da_mon++;
setdate(&d);
}
if(chd==80)
{
newdate[j] =d.da_year--;
setdate(&d);
}
if(chd==72)
{
newdate[j]=d.da_year++;
setdate(&d);
}
if(chd==77&&j==2)
{
cout<<"You can only go back now!";
}
if(chd==75)
{
j--;
}
if(chd==75&&j==0)
{
cout<<"You can only move forward!";
}
if(chd==13)
{
cout<<"The current time is: ";
system("date");
chd=27;
}
}
}
}
void renamee()
{
char oldname[64], newname[64];
cout<<"Enter the name of the file to modify: ";
gets(oldname);
cout<<"\n Enter the new name: ";
gets(newname);
if(rename(oldname,newname)==0)
cout<<"File "<<oldname<<" is now called: "<<newname<<endl;
else
cout<<"error"<<endl;
}
What i need help with is to copy and delete. I was planing on using the SHFileOperation but i'm not familiar with it.
If someone could help me i would really apreciate it, also if anyone know how to make the program code look a little bit more goodlooking i would apreaciate that too.