Unbehandelte Ausnahme bei 0x75A2C6F2 in ConsoleApplication2.exe: Microsoft C++-Ausnahme: std::experimental::filesystem::v1::filesystem_error bei Speic

jackob

Cadet 1st Year
Registriert
Mai 2019
Beiträge
9
Hi

ich schreib ein Programm mit C++, der einen Ordner erstellen muss, und dieser nach aktuellen Datum und Uhrzeit benennen und in diesem Ordner werden dann dateien von anderen Ordner verschoben

da ist den Code :

#include <iostream>
#include "pch.h"
#include <conio.h>
#include <errno.h>
#include <direct.h>
#include <fstream>
#include <stdio.h>
#include <time.h>
#include <iostream>
#include <string>
#include <experimental/filesystem>
#include <ctime>
#include <chrono>
#define _CRT_SECURE_NO_WARNINGS
#include <ctime>
#pragma warning(disable : 4996)

using namespace std;
namespace fs = std::experimental::filesystem;

// Get current date/time, format is YYYY-MM-DD.HH:mm:ss
const std::string currentDateTime() {
time_t now = time(0);
struct tm tstruct;
char buf[80];
tstruct = *localtime(&now);
strftime(buf, sizeof(buf), "%Y-%m-%d.%X", &tstruct);

return buf;
}

int main() {

//d::cout << "currentDateTime()=" << currentDateTime() << std::endl;
//etchar(); // wait for keyboard input
auto dirname = fs::current_path() / currentDateTime();
std::cout << "creating directory " << dirname << "\n";
if (create_directory(dirname)) {
std::cout << "directory didn't exist yet\n";
fs::copy("C:/Users/mousa/Desktop/html", dirname);
getchar();


}
return 0;
}

ich bekomm dann den Fehler : Unbehandelte Ausnahme bei 0x75A2C6F2 in ConsoleApplication2.exe: Microsoft C++-Ausnahme: std::experimental::filesystem::v1::filesystem_error bei Speicherort 0x009CF8B4.

obwohl in CMD wird folgendes ausgeführt : creating directory c:\Users\mousa\source\repos\ConsoleApplication2\ConsoleApplication2\2019-05-16.11:48:38

aber wird keinen ordner erstellt ?


ich hoffe das jemanden mir helfen könnte (;

Vielen Dank
Grüße von Jackob
 
C++:
#include <iostream>
#include "pch.h"
#include <conio.h>
#include <errno.h>
#include <direct.h>
#include <fstream>
#include <stdio.h>
#include <time.h>
#include <iostream>
#include <string>
#include <experimental/filesystem>
#include <ctime>
#include <chrono>
#define _CRT_SECURE_NO_WARNINGS
#include <ctime>
#pragma warning(disable : 4996)

using namespace std;
namespace fs = std::experimental::filesystem;

// Get current date/time, format is YYYY-MM-DD.HH:mm:ss
const std::string currentDateTime() {
  time_t now = time(0);
  struct tm tstruct;
  char buf[80];
  tstruct = *localtime(&now);
  strftime(buf, sizeof(buf), "%Y-%m-%d.%X", &tstruct);

  return buf;
}

int main() {
  //d::cout << "currentDateTime()=" << currentDateTime() << std::endl;
  //etchar(); // wait for keyboard input
  auto dirname = fs::current_path() / currentDateTime();
  std::cout << "creating directory " << dirname << "\n";
  if (create_directory(dirname)) {
    std::cout << "directory didn't exist yet\n";
    fs::copy("C:/Users/mousa/Desktop/html", dirname);
    getchar();
    //fs::em("C:/Users/mousa/Desktop/html");
  }
  return 0;
}

Warum soll man es helfenden auch noch einfach machen? Ich habe das saubere, anständige Formatieren für dich mal übernommen.

greetz
hroessler
 
  • Gefällt mir
Reaktionen: jackob
da hast du Recht, vielen Dank hroessler

Grüsse jackob (;
 
  • Gefällt mir
Reaktionen: hroessler
Ist ein Windows Problem, unter Linux sollte es funktionieren.

Ansonsten kannst du auch Alternativ die Doppelpunkte im Ordnernamen weglassen.
 
  • Gefällt mir
Reaktionen: jackob
ja ist halt ein Windows Problem, aber ich muss ja unter Windows arbeiten !
 
Doppelpunkte im Dateinamen sind nicht zulässig, wie Simpson in seinem Spoiler versteckt hat.
 
  • Gefällt mir
Reaktionen: jackob

Ähnliche Themen

Antworten
10
Aufrufe
942
C
  • Gesperrt
Antworten
10
Aufrufe
1.867
M
Antworten
14
Aufrufe
2.543
M
Zurück
Oben