Скачиваний:
11
Добавлен:
01.05.2014
Размер:
2.67 Кб
Скачать
// lab2.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#define BUFFER_SIZE 255

using namespace std;

void curdir(void);
void sysdir(void);
void shortn(void);

int _tmain(int argc, _TCHAR* argv[])
{
 unsigned int a=0,b=0,c=0;
  system("cls");
  cout<<"\n                                 The second laboratory work\n ";
  cout<<"                               Operations with directory tree\n ";
  getch();
  do
   { 
	system("cls");
    cout<<"\n                                     Menu\n\n\n";
    cout<<" 1.Retrieving current directory,setting of current directory\n\n";
    cout<<" 2.Retrieving the path of the system directory\n\n";
    cout<<" 3.Retrieving the short path form of the specified path\n\n";
    cout<<" 4.Exit\n\n";
    do
	 {
	  cout<<"   Vibirite punkt menu:";
	  fflush(stdin);
      cin>>a;
      if(a<0||a>4)
       {
	    cout<<"\n   Vi dopustili oshibku!!!(1-4)\n";
	    getch();
	   }
	 }
	while(a<0||a>4);
    switch(a)
     {
	  case 1:
	   {
	    curdir();break;
	   }
	  case 2:
	   {   
		sysdir();break;
       }
	  case 3:   
	   {
        shortn();break;
	   }
	 }
   }
  while(a!=4);
  return 0;
}

void curdir(void)
{
 system("cls");
 DWORD length;
 char cur[BUFFER_SIZE],acur[BUFFER_SIZE],a;
 BOOL suc;
 do
  {
   system("cls");
   if(length=GetCurrentDirectory(BUFFER_SIZE,cur))
    {
     cout<<"\nCurrent directory is:\n\n";
     cout<<cur;
     cout<<"\n\nDo you want to set another current directory?(y/n)";
     cin>>a;
     if(a=='Y'||a=='y')
      {
       cout<<"\nInput new current directory path(Format of input: C:\\Windows)\n\n";
       fflush(stdin);
       cin>>acur;
       suc=SetCurrentDirectory(acur);
	   if(suc==NULL)
	    {
         cout<<"\nError while setting new current directory";
	     getch();
	    }
	  }
	}
   else
   {
    cout<<"\nError!!!";  
    getch();
   }
  }
 while(a!='N'&&a!='n');
}

void sysdir(void)
{
 unsigned int res,buf=MAX_PATH;
 char sys[BUFFER_SIZE];
 system("cls");
 if(res=GetSystemDirectory(sys,buf))
  {
   cout<<"\nSystem directory is:\n\n";
   cout<<sys;
   getch();
  }
 else
  {
   cout<<"\nError!!!";  
   getch();
  }
}

void shortn(void)
{
 DWORD res,cache=BUFFER_SIZE;
 char sp[BUFFER_SIZE],lp[BUFFER_SIZE];
 system("cls");
 cout<<"\nSpecify path(Format of input: C:\\Windows):\n\n";
 fflush(stdin);
 cin>>lp;
 if(res=GetShortPathName(lp,sp,cache))
  {
   cout<<"\n\nThe short path form of the specified path is:\n\n";
   cout<<sp;
   getch();
  }
 else
  {
   cout<<"\nError!!!";  
   getch();
  }
}
Соседние файлы в папке 2