Programm funktioniert nicht...
-
das programm sollte eine textdatei öffnen in der Kommentare und Pfade zu Dateien stehen und unterscheiden was Kommentar und was Pfad ist.... (beides beginnt mit /*)
und anschließend die dateien in die richtigen Ordner kopieren...
eine Beispieldatei ist am ende des Threads
das Programm erstellt beim starten eine .ini Datei in der die Pfade stehen....
ach ja und der teil der am anfang der pfade fehlt ist immer gleich und steht auch in der ini
aber irgendwie funktioniert es nicht...
ich such mir jetzt schon seit 2 tagen nen wolf und komm einfach nicht drauf

naja hier der code:
#include <stdio.h> #include <iostream> #include <fstream> #include <stdexcept> #include <string> #include <algorithm> #include <iterator> #include <direct.h> #include <windows.h> using namespace std; /* ***********************************Function CopyData******************************************** */ /* Error Handling + Kopieren der Dateien + erstellen der Ordner */ string CopyData( string zielpfad, string quellpfad, string error, string workdir, string sourcepath) //Definition einer Funktion { string myMkdir = "mkdir ", copy = "Copy /Y "; /*dateiname aus zielpfad löschen */ cout << "\n" << endl; while (zielpfad[zielpfad.length() - 1] != '\\') { zielpfad.erase(zielpfad.length() - 1, 1); } char in[255]; char out[255]; strcpy(in, quellpfad.c_str()); strcpy(out, zielpfad.c_str()); cout << in << endl; cout << out << endl; //lesen std::ifstream ifsIn(in); std::ifstream ifsOut(out); //pruefen if (!ifsIn) {error = error + quellpfad + "\n";} else if (ifsOut) {std::cout << "Ziel existiert bereits\n"; ifsOut.close();} else { //Ordner erstellen und Dateien kopieren cout << "Ordner erstellt" << endl; myMkdir = myMkdir + zielpfad; system(myMkdir.c_str()); copy = copy + quellpfad + " " + zielpfad; system(copy.c_str()); std::ofstream ofsOut(out); char c; while (ifsIn.get(c)) ofsOut.put(c); //schliessen ifsIn.close(); ofsOut.close(); } quellpfad = sourcepath; zielpfad = workdir; myMkdir = "mkdir "; copy = "Copy /Y "; return error; } /* *************************** main *****************************/ int main() { /*Variablen*/ char branch[10]; /* Branch */ char ver[25]; /* Version */ //char line[256]; /* Aktuell eingelesene Zeile */ char compilepath[100]; /* Pfad zum Compilefile */ int pathleght; /* länge des aktuellen Pfades */ int i = 0; /* Hilfsvariable */ char curpath[50]; /* Pfad der .exe */ char temp2[512]; /* Zwischenspeicher */ string comment, quellpfad, zielpfad, error, finalerror, rename = "ren ", move = "move ", del = "rmdir /Q ", myMkdir = "mkdir ", iniName = "BinaryCopy.ini", line; /* Aktuellen Pfad ermitteln + Name der .ini Datei */ getcwd(temp2, 255); std::string temp(temp2); temp = temp + "\\" + iniName; strcpy(curpath, temp.c_str()); std::ifstream LogFile(curpath); if(!LogFile){ /* Wenn die .ini Datei nicht vorhanden ist wird sie erstellt */ WritePrivateProfileString("Allgemein","Branch","B083", curpath); WritePrivateProfileString("Allgemein","Version","41.30.09.07", curpath); WritePrivateProfileString("Pfade","Compilepath","Y:\\Sources\\ADMIN\\B083.compile", curpath); WritePrivateProfileString("Pfade","Arbeitsverzeichnis","C:\\ISS_ENT\\_Versionsdaten", curpath); WritePrivateProfileString("Pfade","Quellverzeichnis","Y:\\Sources",curpath); } DWORD destSize; destSize=500; GetPrivateProfileString("Allgemein","Branch","NULL",branch,destSize, curpath); GetPrivateProfileString("Allgemein","Version","NULL",ver,destSize, curpath); GetPrivateProfileString("Pfade","Compilepath","NULL",compilepath,destSize, curpath); GetPrivateProfileString("Pfade","Arbeitsverzeichnis","NULL",temp2,destSize, curpath); std::string workdir(temp2); zielpfad = workdir + "\\"; GetPrivateProfileString("Pfade","Quellverzeichnis","NULL",temp2,destSize, curpath); std::string sourcepath(temp2); quellpfad = sourcepath + "\\"; /*Compile File einlesen*/ ifstream infile(compilepath); // system(myMkdir.c_str()); while (getline(infile, line)) { comment = line; if (comment[34] == 'Z' && comment[35] == 'U' && comment[36] == 'S'){ i = 1; } if (comment[29] == 'K' && comment[30] == 'O' && comment[31] == 'N'){ i = 0; } if (i == 1){ if ((comment[0] == '/') && (comment[1] == '*')) /* wenn Entwicklerkommentar am Anfang */ { { i = 1; if (comment[3] == 'K' && comment[4] == 'U' || /* KU */ comment[3] == 'M' && comment[4] == 'A' || /* MA */ comment[3] == 'C' && comment[4] == 'H' && comment[5] == 'T' || /* CHT */ comment[3] == 'T' && comment[4] == 'I' && comment[5] == 'N' || /* TIN */ comment[3] == 'P' && comment[4] == 'U' && comment[5] == 'C' || /* PUC */ comment[3] == 'D' && comment[4] == 'O' && comment[5] == 'A' || /* DOA */ comment[3] == 'S' && comment[4] == 'T' && comment[5] == 'R' || /* STR */ comment[3] == 'E' && comment[4] == 'C' && comment[5] == 'P' || /* ECP */ comment[3] == 'G' && comment[4] == 'R' && comment[5] == 'C' || /* GRC */ comment[3] == '*' && comment[4] == '*' && comment[5] == '*' || /* Formatierung */ comment[3] == '-' && comment[4] == '-' && comment[5] == '-' /* Formatierung */ ){/* mach nichts */} else /* wenn es eine Pfadagngabe ist */ { i = 1; pathleght = comment.length(); pathleght = pathleght - 2; comment.erase(pathleght, 2); comment.erase(0, 3); /* BINARY */ if (comment[0] == '$' && comment[1] == 'b' && comment[2] == 'i' || comment[0] == 'B' && comment[1] == 'i' && comment[2] == 'n' || comment[0] == 'B' || comment[0] == 'I' && comment[1] == 'S' && comment[2] == 'S' && comment[3] == '_' && comment[4] == 'C' || comment[0] == 's' && comment[1] == 'r' && comment[2] == 'c' || comment[7] == '$' && comment[8] == 'b' && comment[9] == 'i' || comment[7] == 'B' && comment[8] == 'i' && comment[9] == 'n' || comment[7] == 'B' || comment[7] == 'I' && comment[8] == 'S' && comment[9] == 'S' && comment[10] == '_' && comment[11] == 'C' || comment[7] == 's' && comment[8] == 'r' && comment[9] == 'c' || comment[10] == '$' && comment[11] == 'b' && comment[12] == 'i' || comment[10] == 'B' && comment[11] == 'i' && comment[12] == 'n' || comment[10] == 'B' || comment[10] == 'I' && comment[11] == 'S' && comment[12] == 'S' && comment[13] == '_' && comment[14] == 'C' || comment[10] == 's' && comment[11] == 'r' && comment[12] == 'c') { if (comment[0] == 'C' && comment[1] == 'O' && comment[2] == 'M' && comment[3] == 'M' && comment[4] == 'O' && comment[5] == 'N' || comment[0] == 'C' && comment[1] == 'o' && comment[2] == 'm' && comment[3] == 'm' && comment[4] == 'o' && comment[5] == 'n' || comment[0] == 'c' && comment[1] == 'o' && comment[2] == 'm' && comment[3] == 'm' && comment[4] == 'o' && comment[5] == 'n') {comment.erase(0, 7);} if (comment[0] == 'I' && comment[1] == 'S' && comment[2] == 'S' && comment[3] != '_' || comment[0] == 'I' && comment[1] == 's' && comment[2] == 's' && comment[3] != '_' || comment[0] == 'i' && comment[1] == 's' && comment[2] == 's' && comment[3] != '_') {comment.erase(0, 4);} if (comment[0] == '$' && comment[1] == 'b' && comment[2] == 'i' && comment[3] == 'n' || comment[0] == 's' && comment[1] == 'r' && comment[2] == 'c') { zielpfad = zielpfad + ver + "\\Temp" + "\\ISS\\" + comment; } else{ zielpfad = zielpfad + ver + "\\Temp" + "\\COMMON\\" + comment; } quellpfad = quellpfad + "BINARY\\" + comment; finalerror = finalerror + CopyData(zielpfad, quellpfad, error, workdir, sourcepath); /* Aufruf der function */ quellpfad = sourcepath; zielpfad = workdir; } /* ISS */ else if (comment[0] == '$' || comment[0] == 'I' && comment[1] == 'S' && comment[2] == 'S') { /* ISS/CFG */ if (comment[0] == 'I' && comment[1] == 'S' && comment[2] == 'S') { zielpfad = zielpfad + ver + "\\Temp" + "\\" + comment; quellpfad = quellpfad + "ISS_" + branch + "\\" + comment; finalerror = finalerror + CopyData(zielpfad, quellpfad, error, workdir, sourcepath); /* Aufruf der function */ quellpfad = sourcepath; zielpfad = workdir; } /* ISS */ else{ zielpfad = zielpfad + ver + "\\Temp" + "\\ISS\\" + comment; quellpfad = quellpfad + "ISS_" + branch + "\\ISS\\" + comment; finalerror = finalerror + CopyData(zielpfad, quellpfad, error, workdir, sourcepath); /* Aufruf der function */ quellpfad = sourcepath; zielpfad = workdir; } } /* COMMON/CFG */ else if (comment[0] == 'C' && comment[1] == 'O' && comment[2] == 'M' && comment[3] == 'M' && comment[4] == 'O' && comment[5] == 'N' || comment[0] == 'C' && comment[1] == 'o' && comment[2] == 'm' && comment[3] == 'm' && comment[4] == 'o' && comment[5] == 'n' || comment[0] == 'c' && comment[1] == 'o' && comment[2] == 'm' && comment[3] == 'm' && comment[4] == 'o' && comment[5] == 'n') { zielpfad = zielpfad + ver + "\\Temp" + "\\" + comment; quellpfad = quellpfad + "ISS_" + branch + "\\" + comment; finalerror = finalerror + CopyData(zielpfad, quellpfad, error, workdir, sourcepath); /* Aufruf der function */ quellpfad = sourcepath; zielpfad = workdir; } /* COMMON */ else { zielpfad = zielpfad + ver + "\\Temp" + "\\COMMON\\" + comment; quellpfad = quellpfad + "ISS_" + branch + "\\COMMON\\" + comment; finalerror = finalerror + CopyData(zielpfad, quellpfad, error, workdir, sourcepath); /* Aufruf der function */ quellpfad = sourcepath; zielpfad = workdir; } } } } } /* Ordner richtig benennen und ins richtige Verzeichnis verschieben */ rename = rename + zielpfad + ver + "\\Temp\\" + "ISS" + " ISS_BIN_U"; system(rename.c_str()); rename = "ren "; rename = rename + zielpfad + ver + "\\Temp\\" + "COMMON" + " COMMON_BIN_U"; system(rename.c_str()); move = move + zielpfad + ver + "\\Temp\\" + "ISS_BIN_U " + zielpfad + ver; system(move.c_str()); move = "move "; move = move + zielpfad + ver + "\\Temp\\" + "COMMON_BIN_U " + zielpfad + ver; system(move.c_str()); del = del + zielpfad + ver + "\\Temp\\"; system(del.c_str()); /* Ausgabe der gefundenen Fehler */ cout << "\n************************************************\n" << endl; cout << "Fehler:\n" << endl; cout << finalerror << endl; cout << "\n************************************************\n" << endl; cout << "Wenn Fehler aufgetreten sind:\n" << endl; cout << "* bei Binary Dateien darf kein ISS oder Common im Pfad vorhanden sein" << endl; cout << "* AUSNAHME: Bei Dateien im CFG Verzeichnis" << endl; cout << "* Tippfehler" << endl; cout << "* liegt die Datei wirklich in dem Ordner?" << endl; cout << "* falls der Fehler weiterhin auftritt: Datei einfach per Hand kopieren \n\n" << endl; /* ************************************* /BINARYS NACH COMPILEFILE *************************** */ cout << "Beliebige Taste drücken um Fortzufahren\n" << endl; system("pause"); return 0; } }und hier die beispieldatei (in .txt speichern
) :/* **************************************************************************** */ /* ******************** ZUSÄTZLICH ********************** */ /* ******************** ZU KOPIERENDE DATEIEN ********************** */ /* **************************************************************************** */ /* DOA2008 Kommentar kommentar */ /* Test\test.txt */ /* DOA2008 Kommentar kommentar */ /* Test\test2.txt */ /* DOA2008 Kommentar kommentar */ /* Test\test3.txt */danke schonmal für eure hilfe!
btw. ich weiss das mein code alles andere als gut ist aber das ist eins meiner ersten projekte...bin also noch am lernen und probieren

-
Masternoob schrieb:
aber irgendwie funktioniert es nicht...
Lerne bitte ausreichende Fehlermeldungen zu verfassen. Was funktioniert nicht, oder verhält sich anders als geplant? Gibt der Compiler Fehlermeldungen oder Warnungen aus (Dann bitte die ersten paar angeben)?
Ich werde mich jedenfalls nicht ohne weitere Angaben durch einen Code kämpfen der
a) vermutlich nicht in dieses Forum passt (ANSI C++, nicht Windows API, für letzteres gibt es ein eigenes Forum)
b) noch recht schlecht lesbar istEdit:
btw. ich weiss das mein code alles andere als gut ist aber das ist eins meiner ersten projekte...bin also noch am lernen und probieren
Das sollte gerade ein Grund sein noch die Windows API wegzulassen, und erstmal mit C++ vertraut zu werden (Und auch der C++ Standardbibliothek, alleine schon mit std::string & co).
cu André
-
asc schrieb:
Masternoob schrieb:
aber irgendwie funktioniert es nicht...
Lerne bitte ausreichende Fehlermeldungen zu verfassen. Was funktioniert nicht, oder verhält sich anders als geplant? Gibt der Compiler Fehlermeldungen oder Warnungen aus (Dann bitte die ersten paar angeben)?
Ich werde mich jedenfalls nicht ohne weitere Angaben durch einen Code kämpfen der
a) vermutlich nicht in dieses Forum passt (ANSI C++, nicht Windows API, für letzteres gibt es ein eigenes Forum)
b) noch recht schlecht lesbar istEdit:
btw. ich weiss das mein code alles andere als gut ist aber das ist eins meiner ersten projekte...bin also noch am lernen und probieren
Das sollte gerade ein Grund sein noch die Windows API wegzulassen, und erstmal mit C++ vertraut zu werden (Und auch der C++ Standardbibliothek, alleine schon mit std::string & co).
cu André
Compiler gibt keine Fehlermeldungen aus...
hab mal n paar Messages eingebaut und anscheined liest das prog nur die erste zeile ein und hört dann auf...
-
Hallo
kennst du den Debugger?
chrische
-
chrische5 schrieb:
Hallo
kennst du den Debugger?
chrische
.....
ja kenn ich...und wenn er mir geholfen hätte wäre ich nicht hier :p
-
Weisst Du, wie man den Debugger benutzt?
Mit "Anhalten" und "einen Schritt weiter" sollte man hervorragend ermitteln können, warum er nur die erste Zeile einliest (bzw. welche Bedingung für einen Abbruch sorgt).
-
chrische5 schrieb:
kennst du den Debugger?
das forum ist sein debugger.
-
ok...hab inzwischen was gefunden...
und zwar wird die variable "zielpfad" nicht gefüllt, bzw. nicht aus der ini datei ausgelesen:
std::ifstream LogFile(curpath); if(!LogFile){ /* Wenn die .ini Datei nicht vorhanden ist wird sie erstellt */ WritePrivateProfileString("Allgemein","Branch","B083", curpath); WritePrivateProfileString("Allgemein","Version","41.30.09.07", curpath); WritePrivateProfileString("Pfade","Compilepath","Y:\\Sources\\ADMIN\\B083.compile", curpath); WritePrivateProfileString("Pfade","Arbeitsverzeichnis","C:\\ISS_ENT\\_Versionsdaten", curpath); WritePrivateProfileString("Pfade","Quellverzeichnis","Y:\\Sources",curpath); } DWORD destSize; destSize=500; GetPrivateProfileString("Allgemein","Branch","NULL",branch,destSize, curpath); GetPrivateProfileString("Allgemein","Version","NULL",ver,destSize, curpath); GetPrivateProfileString("Pfade","Compilepath","NULL",compilepath,destSize, curpath); GetPrivateProfileString("Pfade","Arbeitsverzeichnis","NULL",temp2,destSize, curpath); std::string workdir(temp2); zielpfad = workdir + "\\"; GetPrivateProfileString("Pfade","Quellverzeichnis","NULL",temp2,destSize, curpath); std::string sourcepath(temp2); quellpfad = sourcepath + "\\";das gleiche mit sourcepath...
hat jemand eine idee woran das liegt?
-
Hi,
wo ist der eigentliche Sinn deines Programms?