#include <direct.h>
#include <dos.h>
#include <sys\stat.h>
#include <string.h>
#include <stdio.h>
#include <fcntl.h>
#include <io.h>
#include<conio.h>
#include<iostream.h>
#include<stdlib.h>
void mov()
{ FILE *file2;
int file1;
char *msg;
char ch;
char *name1,*name2;
/* create a file */
cout<<"enter name of file\n";
cin>>name1>>name2;
file1 = open(name1,
O_CREAT | O_RDWR,
S_IREAD | S_IWRITE);
file2 = fopen(name2, "w");
/* reads chars from the file until it reaches EOF */
do
{
read(file1,&ch,1);
//
fprintf(file2,"",ch);
fwrite(&ch, sizeof(ch), 1,file2);
} while (!eof(file1));
/* delete the file */
remove((name1));
//fclose(file1);
}
void chdir()
{ char *c="c",*d="d",*e="e",*driv,*f="f";
int ptr;
clrscr();
cout<<"enter the the driv [c] or [d] or[e]or[f]\n";
cin>>driv;
ptr=strcmp(driv,c);
if(ptr==0)
{
if (_chdrive(3) == 0)
printf("Successfully changed to drive C:\n");
}
else
{
ptr=strcmp(driv,d);
if(ptr==0)
{
if (_chdrive(4) == 0)
printf("Successfully changed to drive D:\n");
}
else
{
ptr=strcmp(driv,e);
if(ptr==0)
{
if (_chdrive(5) == 0)
printf("Successfully changed to drive E:\n");
}
else
{ptr=strcmp(driv,f);
if(ptr==0)
{
if (_chdrive(6) == 0)
printf("Successfully changed to drive F:\n");
}
printf("Cannot change to drive :\n");}}}
unsigned disk;
_dos_getdrive(&disk);
printf("The current drive is: %c\n", disk + 'A' - 1);
getch();
}
//////////////////////////
void ls()
{ //mohammed alnahmi
struct ffblk file;
int done;
cout<<"Directory listing of *.*\n";
done = findfirst("*.*",&file,0);
while (!done)
{ // textcolor(3);
cprintf(" ");
textcolor(3);
cout<<file.ff_name<<"\n";
done = findnext(&file);
}
}
void dir()
{
char curdir[MAXPATH];
char disk;
disk = _getdrive()+'a' - 1;
getcurdir(0,curdir);
printf("The current directory is %c\\%s\n",disk, curdir);
}
/////////////////////////////////////
void clear()
{
cout<<"now will clear screenafter [3] second......";
for(int i=1;i<=3;i++)
{
sleep(1);
textcolor(1);
cprintf("%d",i);
}
clrscr();
}
/////////////////////////////////////////////
void wc(){//to print number of word in file
int handle;
char ch;
int n=0;
char *name;
/* create or open file */
cout<<"enter name of file\n";
cin>>name;
handle = open(name,
O_CREAT | O_RDWR,
S_IREAD | S_IWRITE
);
lseek(handle, 0L, SEEK_SET);
/* reads chars from the file until it reaches EOF */
do
{
read(handle, &ch, 1);
if(ch==' ') n++;
} while (!eof(handle));
printf("WC IN THES FILE=[%d]",n);
close(handle);
} //////////////////////////////////////////////////////
void cat(){ //to display content file in monitor
int file;
char *msg;
char ch;
char *name;
/* create a file */
cout<<"enter name of file\n";
cin>>name;
file = open(name,
O_CREAT | O_RDWR,
S_IREAD | S_IWRITE
);
lseek(file, 0L, SEEK_SET);
printf("the file content is:\n");
/* reads chars from the file until it reaches EOF */
do
{
read(file, &ch, 1);
printf("%c", ch);
} while (!eof(file));
close(file);
}
/////////////////////////////////////
void writ_file()
{
char *name,string[100];
FILE *stream;
cout<<" enter name file \n";
cin>>name;
stream = fopen(name, "w");
/* open file$$ */
gets(string);
fprintf(stream,"%s",string);
fclose(stream);
}
void cpy(){ //to display content file in monitor
FILE *file2;
int file1;
char *msg;
char ch;
char *name1,*name2;
/* create a file */
cout<<"enter name of file\n";
cin>>name1>>name2;
file1 = open(name1,
O_CREAT | O_RDWR,
S_IREAD | S_IWRITE);
file2 = fopen(name2, "w");
/* reads chars from the file until it reaches EOF */
do
{
read(file1,&ch,1);
//
fprintf(file2,"",ch);
fwrite(&ch, sizeof(ch), 1,file2);
} while (!eof(file1));
//fclose(file1);
}
struct history
{
char comman[10] ;
}
histor[11];
int main(void)
{
int ptr,i=0;
char *command,*out="q";
char *history[10];
char *buf1="ls",*buf2="dir",*buf3="clear",*buf4="copy";
char *buf5="wc",*buf6="cat>",*buf7="cat",*buf8="history",*buf9="chdir";
char *buf10="mov";
clrscr();
for(;{
cout<<"\n\n\nenter thes word to work\n";
cout<<"\n1-[wc] to know number of word in file\n" ;
cout<<"\n2-[cat] to creat or open file and write in file\n";
cout<<"\n3-[cat>] to print content file into screen\n" ;
cout<<"\n4-[dir] to know where now you path or dirctory\n" ;
cout<<"\n5-[ls] to print all file active dirctory\n";
cout<<"\n6-[clear] to clear screen\n";
cout<<"\n7-[copy] to copy file from another file\n";
cout<<"\n8-[history] to print all command you enterd it\n";
cout<<"\n9-[chdir] to chang current drive\n";
cout<<"\n10-[mov] to chang file dairectory\n";
cout<<"\n[q] to exite()\n\n\n\n";
for(int i=1;i<=10;i++){
cin>>histor[i].comman;
ptr= strcmp(histor[i].comman,buf8);
if(ptr==0)
{
for(int y=1;y<=i;y++)
printf("%s\n",histor[y].comman);}
else{
ptr= strcmp(histor[i].comman,buf1);
if(ptr==0)
{ ls();
}
else
{ ptr= strcmp(histor[i].comman,buf2);
if(ptr==0)
{ dir();
}
else
{ ptr= strcmp(histor[i].comman,buf3);
if(ptr==0)
{clear();
}
else
{ ptr= strcmp(histor[i].comman,buf4);
if(ptr==0)
{ cpy();
}
else
{ ptr= strcmp(histor[i].comman,buf5);
if(ptr==0)
{ wc();
}
else
{
ptr= strcmp(histor[i].comman,buf6);
if(ptr==0)
{
writ_file();
}
else
{
ptr= strcmp(histor[i].comman,buf7);
if(ptr==0)
{
cat();
}
else
{
ptr= strcmp(histor[i].comman,out);
if(ptr==0)
{
exit(-1);
}
else
{ ptr=strcmp(histor[i].comman,buf9);
if(ptr==0)
{chdir();
}
else
{ ptr=strcmp(histor[i].comman,buf10);
if(ptr==0)
{
mov();
}
else
{
cout<<"no command\n";} }}}}}}}}} }} } }
الأحد يوليو 10, 2011 8:54 am من طرف أحمدالسيدالصعيدي
» الشبكات NETWORKS
الجمعة ديسمبر 17, 2010 9:58 pm من طرف THE DRAGON
» صفارات BIOS
الجمعة ديسمبر 17, 2010 9:54 pm من طرف THE DRAGON
» proxy >>>بروكسي
الجمعة ديسمبر 17, 2010 9:44 pm من طرف THE DRAGON
» بدك تحرم الضحيه على انو يفوت على الياهوو مسنجر او على ايماله الخاص
الخميس ديسمبر 02, 2010 5:26 am من طرف bibeto008
» قصيدة باللغة الانكليزية
الأحد نوفمبر 28, 2010 12:51 am من طرف lana
» مهم جداً...............
السبت نوفمبر 27, 2010 1:09 pm من طرف عاشق الاحساس
» اصابة الاربطة المتصالبة للركبة
الجمعة نوفمبر 26, 2010 5:24 pm من طرف THE DRAGON
» كبار السن و الرياضة
الجمعة نوفمبر 26, 2010 5:21 pm من طرف THE DRAGON