Добавил:
Studfiles2
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Лабораторная работа1 / main2
.cpp#include <windows.h>
#include <iostream>
#include <conio.h>
#include <string>
using namespace std;
TCHAR Buffer[256];
TCHAR _Buffer[256];
int CreateDelete(int*);
int Info(void);
int ChangeDir(void);
int CopyMove(int * a);
int main()
{
int in;
int i=1;
while(i)
{
system("cls");
cout<<" ::Choose one::\n"<<endl;
cout<<" 1 > Information"<<endl;
cout<<" 2 > Create\\Delete"<<endl;
cout<<" 3 > ChangeDir"<<endl;
cout<<" 4 > Copy\\Move Files"<<endl;
cout<<" 0 > Exit\n"<<endl;
cout<<" You choose: ";
cin>>in;
switch(in)
{
case 1:
Info();
break;
case 2:
CreateDelete(&in);
break;
case 3:
ChangeDir();
break;
case 4:
CopyMove(&in);
break;
case 0:
i=0;
}
}
return 0;
}
int Info()
{
system("cls");
GetCurrentDirectory(256, Buffer);
cout<<"Current directory > "<<Buffer<<endl;
GetWindowsDirectory(Buffer,256);
cout<<"Windows directory > "<<Buffer<<endl;
GetSystemDirectory(Buffer,256);
cout<<"Windows system directory > "<<Buffer<<endl;
getch();
return 0;
}
int ChangeDir()
{
while(1)
{
system("cls");
GetCurrentDirectory(256, Buffer);
cout<<"Current directory > "<<Buffer<<endl;
cout<<"\nNew directory > ";
cin>>Buffer;
if(!SetCurrentDirectory(Buffer))
{
cout<<"Directory dosn't exist.";
getch();
}
else
break;
}
return 0;
}
int CreateDelete(int * a)
{
int i=1;
while(i)
{
system("cls");
cout<<" 1 > Create directory"<<endl;
cout<<" 2 > Delete directory"<<endl;
cout<<" 0 > Return\n"<<endl;
cout<<" You choose: ";
cin>>*a;
switch(*a)
{
case 1:
cout<<"\n Please enter path directory to create > ";
cin>>Buffer;
CreateDirectory(Buffer,NULL);
break;
case 2:
cout<<"\n Please enter path directory to delete > ";
cin>>Buffer;
RemoveDirectory(Buffer);
if(GetLastError()==145)
{
cout<<"\n The directory is not empty. You can't delete it.";
getch();
}
break;
case 0:
i=0;
}
}
return 0;
}
int CopyMove(int * a)
{
char tmp;
int error=0;
int i=1;
while(i)
{
system("cls");
cout<<" 1 > Copy File"<<endl;
cout<<" 2 > Move File"<<endl;
cout<<" 0 > Return\n"<<endl;
cout<<" You choose: ";
cin>>*a;
switch(*a)
{
case 1:
cout<<"\n Copy from > ";
cin>>Buffer;
cout<<" Copy to > ";
cin>>_Buffer;
CopyFile(Buffer,_Buffer,1);
error=GetLastError();
switch(error)
{
case 2:
cout<<"\nCan't find the file.";
getch();
break;
case 3:
cout<<"\nCan't find the folder.";
getch();
break;
case 80:
do
{
system("cls");
cout<<"File is already exist. Rewrite file? (Y\\N) > ";
cin>>tmp;
}
while(tmp!='Y' && tmp!='y' && tmp!='N' && tmp!='n');
if(tmp=='Y' || tmp=='y')
CopyFile(Buffer,_Buffer,1);
break;
case 0:
break;
}
break;
case 2:
cout<<"\n Move from > ";
cin>>Buffer;
cout<<" Move to > ";
cin>>_Buffer;
MoveFile(Buffer,_Buffer);
cout<<GetLastError();
error=GetLastError()
switch(error)
{
case 2:
cout<<"\nCan't find the file.";
getch();
break;
case 3:
cout<<"\nCan't find the folder.";
getch();
break;
}
break;
case 0:
i=0;
}
}
return 0;
}
Соседние файлы в папке Лабораторная работа1