Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Лабораторная работа №2

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

#include <iostream.h>
#include <stdio.h>
#include <windows.h>
#include <stdlib.h>
#include <conio.h>

void main(void){

	int choice;
    TCHAR string_new[MAX_PATH];
    TCHAR string_exist[MAX_PATH];
	do{
		system("cls");

		cout<<"1. Get Current Directory\n";
		cout<<"2. Set Current Directory\n";
		cout<<"3. Get Windows Directory\n";
        cout<<"4. Create Directory\n";
		cout<<"5. Delete File\n";
		cout<<"6: MoveFileEx\n";
		cout<<"7. Exit\n";
		cout<<"\nEnter your choice: ";
		cin>>choice;
		TCHAR infoBuf[MAX_PATH];
	    DWORD  bufCharCount=MAX_PATH;
		switch(choice){
			case 1: bufCharCount = MAX_PATH;
					if( !GetCurrentDirectory( bufCharCount,infoBuf ) )
						printf("Error");
					else
					    printf("Current directory: %s\n",infoBuf);
					getch();

				    break;
            case 2: TCHAR newCurPath[MAX_PATH];

					printf("Input new current directory name: ");
					cin>>newCurPath;
					if( !SetCurrentDirectory( newCurPath ) )
						printf("Error");
					if( !GetCurrentDirectory( bufCharCount,infoBuf ) )
						printf("Error");
					else
					    printf("Current directory: %s\n",infoBuf);
					getch();       

				    break;
            case 3: if( !GetWindowsDirectory( infoBuf, bufCharCount ) )
						printf("Error");
					else
					    printf("Windows directory: %s\n",infoBuf);
					getch();

				    break;
			case 4: LPSECURITY_ATTRIBUTES securityAttributes;
					securityAttributes = 0;
					cout<<"Input directory name: ";
					cin>>string_new;
					if( !CreateDirectory( string_new, securityAttributes ) ){
						cout<<"Error";
						getch();
					}
                    cout<<flush;
					getch();

				    break;
			case 5:cout<<"Input file name: ";
					cin>>string_new;
					if( !DeleteFile(string_new) )
					{
			         cout<<"Error";
					 getch();
					}
				    cout<<flush;
		     	  	break;
			case 6:  cout<<"\nInsert an existing name of a file: ";
                   cin>>string_exist;
                   cout<<"\nInsert a new name of a file: ";
                   cin>>string_new;
                   if(MoveFileEx(string_exist,string_new,MOVEFILE_WRITE_THROUGH))
                    cout<<"Operation is executed successfully!\n";
                   else cout<<"error";
                    cout<<flush;
            	   break;

			case 7:break;
            default: cout<<"Error";
				     getch();
		}
	}while(choice!=7);
}