Добавил:
Studfiles2
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Лабораторная работа №37 / 3 / lab3
.cpp// lab3sanch.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#define BUFFER_SIZE 255
using namespace std;
void newdir(void);
void remdir(void);
void movefile(void);
void delfile(void);
int _tmain(int argc, _TCHAR* argv[])
{
unsigned int a=0,b=0,c=0;
system("cls");
cout<<"\n The third laboratory work\n ";
cout<<" Operations with directories and files\n ";
getch();
do
{
system("cls");
cout<<"\n Menu\n\n\n";
cout<<" 1.Operations with directories\n\n";
cout<<" 2.Operations with files\n\n";
cout<<" 3.Exit\n\n";
do
{
cout<<" Vibirite punkt menu:";
fflush(stdin);
cin>>a;
if(a<0||a>3)
{
cout<<"\n Vi dopustili oshibku!!!(1-3)\n";
getch();
}
}
while(a<0||a>3);
switch(a)
{
case 1:
{
system("cls");
cout<<"\n Menu\n\n\n";
cout<<" 1.Create directory\n\n";
cout<<" 2.Remove directory\n\n";
cout<<" Vibirite punkt menu:";
fflush(stdin);
cin>>b;
if(b<0||b>2)
{
cout<<"\n Vi dopustili oshibku!!!(1-2)";
cout<<"\n Nagmite lubuu klavishu\n";
getch();
}
switch(b)
{
case 1:
{
newdir();break;
}
case 2:
{
remdir();break;
}
}
break;
}
case 2:
{
system("cls");
cout<<"\n Menu\n\n\n";
cout<<" 1.Move file\n\n";
cout<<" 2.Delete file\n\n";
cout<<" Vibirite punkt menu: ";
fflush(stdin);
cin>>c;
if(c<0||c>2)
{
cout<<"\n Vi dopustili oshibku!!!(1-2)";
cout<<"\n Nagmite lubuu klavishu\n";
getch();
}
switch(c)
{
case 1:
{
movefile();break;
}
case 2:
{
delfile();break;
}
}
break;
}
}
}
while(a!=3);
return 0;
}
void newdir(void)
{
char dirpath[248];
system("cls");
cout<<"\n\n\n\nSpecify the new directory path:\n\n";
fflush(stdin);
gets(dirpath);
if(!CreateDirectory(dirpath, NULL))
{
if(GetLastError()==ERROR_ALREADY_EXISTS)
{
cout<<"\n\nThe specified directory already exists.";
getch();
}
else
{
cout<<"\n\nCouldn't create new directory.";
getch();
}
}
else
{
cout<<"\n\nThe new directory successfully created!";
getch();
}
}
void remdir(void)
{
char dirpath[MAX_PATH];
system("cls");
cout<<"\n\n\n\nSpecify the directory to be removed:\n\n";
fflush(stdin);
gets(dirpath);
if(RemoveDirectory(dirpath))
{
cout<<"\n\nSpecified directory was succesfully removed!";
getch();
}
else
{
cout<<"\n\nError!!!(maybe the directory is not empty)";
getch();
}
}
void movefile(void)
{
char old[255];
char newn[255];
system("cls");
cout<<"\n\n\n\nSpecify the name of the file that will be moved:\n\n";
fflush(stdin);
gets(old);
cout<<"\n\n\n\nSpecify the new name of the file :\n\n";
fflush(stdin);
gets(newn);
if(MoveFile(old,newn))
{
cout<<"\n\nSpecified file was succesfully moved!"<<endl;
getch();
}
else
{
cout<<"\n\nError!!!"<<endl;
getch();
}
}
void delfile(void)
{
char file[MAX_PATH ];
system("cls");
cout<<"\n\n\n\nSpecify the name of the file to be deleted:\n\n";
fflush(stdin);
gets(file);
if(DeleteFile(file))
{
cout<<"\n\nSpecified file was succesfully deleted!";
getch();
}
else
{
if(GetLastError()==ERROR_ACCESS_DENIED)
{
cout<<"\n\nThe specified file is read-only.";
getch();
}
else
{
cout<<"\n\nError!!!(maybe the specified file does not exist).";
getch();
}
}
}