lundi 30 mars 2015

C++ to make some complex directory

I have a program:



#include <iostream>
#include <string>
#include <windows.h>
using namespace std;

int main(int argc, char** argv) {
HANDLE hConsole;
string x;
int conta=0;
int virgole = 0x22;
int error;
int backslash = 0x5c;
string destinazione;
string testo;
string print;
string xcopy ("xcopy /e /i ");
string origine ("prog vuoto");
string spazio (" ");
char sbarra = backslash;
char virgolette = virgole;
hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
do{
error=0;
conta ++;
cout<<"inserisci il nome della cartella: "; //don't warry it's italian. translate: insert the directory name:
SetConsoleTextAttribute(hConsole,11); //this changes the text color
getline (cin, testo);
SetConsoleTextAttribute(hConsole, 7);
if (testo.find("/")!=string::npos){ //now i check for every denyed character
error=1;
}else if (testo.find(".")!=string::npos){
error=1;
}else if (testo.find("<")!=string::npos){
error=1;
}else if(testo.find(">")!=string::npos){
error=1;
}else if(testo.find("?")!=string::npos){
error=1;
}else if(testo.find("|")!=string::npos){
error=1;
}else if(testo.find(virgolette)!=string::npos){
error=1;
}else if(testo.find("*")!=string::npos){
error=1;
}else if(testo.find(":")!=string::npos){
error=1;
}else if(testo.find(sbarra)!=string::npos){
error=1;
}else

if(testo.empty()){ //now for empty name or name whit only a space
error=2;
}else if(testo.find(" ")==0){
error=3;
}
switch(error){

case 1: SetConsoleTextAttribute(hConsole, 12);
cout<<endl<<"ERROR"<<endl;
SetConsoleTextAttribute(hConsole, 7);
cout<<"il nome di una cartella non puo contenere"<<endl; //translate: a directory name could not have
cout<<" < > | * ? : / "<<sbarra<<" "<<virgolette<<" ."<<endl<<endl; // < > | * ? : / \ " .
break;
case 2: SetConsoleTextAttribute(hConsole,12);
cout<<endl<<"ERROR"<<endl;
SetConsoleTextAttribute(hConsole, 7);
cout<<"non hai inserito alcun nome"<<endl<<endl; //translate: you haven't writen any name.
break;
case 3: SetConsoleTextAttribute(hConsole, 12);
cout<<endl<<"ERROR"<<endl;
SetConsoleTextAttribute(hConsole, 7);
cout<<"una cartella non puo chiamarsi "<<virgolette<<" "<<virgolette<<"(spazio)"<<endl<<endl; //translate: a directory couldn't be called " "(space)
break;
default: break;;

}
if (conta==4){ //this check i you have done too errors
SetConsoleTextAttribute(hConsole, 12);
cout<<endl<<" TROPPI ERRORI: PULIZIA SCHERMO"; //translate: TOO MANY ERRORS: SCREEN CLEANING
SetConsoleTextAttribute(hConsole, 0);
cin.ignore();
SetConsoleTextAttribute(hConsole, 12);
system("cls");
cout<<endl<<" TROPPI ERRORI:";
SetConsoleTextAttribute(hConsole, 10);
cout<<" PULIZIA SCHERMO EFFETTUATA"<<endl<<endl; //translate: TOO MANY ERRORS: SCREEN CLEANING DONE
SetConsoleTextAttribute(hConsole, 7);
conta=0;
}else if(error){
cout<<"per favore "; //this add "please" word before "insert the directory name
}
}while(error);

destinazione = virgolette + testo + virgolette; //this create the dos command
print = xcopy + virgolette + origine + virgolette + spazio + destinazione;
system(print.c_str()); //this sends the dos command
cout << endl<< "premi invio quando hai finito ..."; //translate: press enter when finished ...
SetConsoleTextAttribute(hConsole, 0);
getline (cin, x);
exit;
return 0;
}


base directory content


Now at this time this program will point a base directory called "prog vuoto" copy it and than paste it with the name you insert.


So this program will need that there is a directory called "prog vuoto" in the same directory of the exe file.


I need a way to have the same result but without the base directory.


Example: I put this program in a empty directory, I launch it and then insert the name "test".


Is it possible?


Aucun commentaire:

Enregistrer un commentaire