<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[CreateDirectory Probleme]]></title><description><![CDATA[<p>Moin,</p>
<p>folgendes möchte ich Realisieren:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;Windows.h&gt;
#include &lt;fstream&gt;
using namespace std;

int main(void){

	string name, kuerzel, age, funktion;
	string spath = &quot;test\\&quot;; // Ordner test bereits vorhanden
	fstream save;

	// Eingabe der Daten
	cout &lt;&lt; &quot;Name: &quot;;
	getline(cin, name);
	cout &lt;&lt; &quot;Kuerzel: &quot;;
	getline(cin, kuerzel);
	cout &lt;&lt; &quot;Alter: &quot;;
	getline(cin, age);
	cout &lt;&lt; &quot;Funktion: &quot;;
	getline(cin, funktion);

	// Ordner [kuerzel] in test\ erstellen

	// Abfrage ob der Ordner schon vorhanden ist
	// Ordner [kuerzel] schon vorhanden -&gt; Abfrage: Überschreiben? (y/n)
	// Ordner [kuerzel] nicht vorhanden -&gt; neu erstellen
	CreateDirectory(&quot; &quot;, NULL);

	// Daten in test\[kuerzel]\ als .txt Datei abspeichern

	spath += kuerzel;
	spath += &quot;\\&quot;;
	spath += kuerzel;
	spath += &quot;.txt&quot;;
	save.open(spath.c_str(), ios::out|ios::trunc);
	if(save.is_open() != true){
		cout &lt;&lt; &quot;\nFehler beim oeffnen der Datei!\n\n&quot;;
		system(&quot;PAUSE&quot;);
		exit(1);
	}
	save &lt;&lt; &quot;Name: &quot; &lt;&lt; name &lt;&lt; endl
		 &lt;&lt; &quot;Alter: &quot; &lt;&lt; age &lt;&lt; endl
		 &lt;&lt; &quot;Funktion: &quot; &lt;&lt; funktion &lt;&lt; endl;
	save.close();
	cout &lt;&lt; &quot;\nDatei wurde erfolgreich erstellt\n\n&quot;;
	system(&quot;PAUSE&quot;);
	return 0;
}
</code></pre>
<p>Nur stelle ich jetzt fest, das ich überhaupt keinen Plan habe wie ich das mit CreateDirectory verwirklichen kann. Dazu muss ich sagen, ich habe mit CreateDirectory noch nie gearbeitet...</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/276145/createdirectory-probleme</link><generator>RSS for Node</generator><lastBuildDate>Wed, 26 Aug 2026 11:47:34 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/276145.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 27 Oct 2010 14:52:16 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to CreateDirectory Probleme on Wed, 27 Oct 2010 14:52:41 GMT]]></title><description><![CDATA[<p>Moin,</p>
<p>folgendes möchte ich Realisieren:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;Windows.h&gt;
#include &lt;fstream&gt;
using namespace std;

int main(void){

	string name, kuerzel, age, funktion;
	string spath = &quot;test\\&quot;; // Ordner test bereits vorhanden
	fstream save;

	// Eingabe der Daten
	cout &lt;&lt; &quot;Name: &quot;;
	getline(cin, name);
	cout &lt;&lt; &quot;Kuerzel: &quot;;
	getline(cin, kuerzel);
	cout &lt;&lt; &quot;Alter: &quot;;
	getline(cin, age);
	cout &lt;&lt; &quot;Funktion: &quot;;
	getline(cin, funktion);

	// Ordner [kuerzel] in test\ erstellen

	// Abfrage ob der Ordner schon vorhanden ist
	// Ordner [kuerzel] schon vorhanden -&gt; Abfrage: Überschreiben? (y/n)
	// Ordner [kuerzel] nicht vorhanden -&gt; neu erstellen
	CreateDirectory(&quot; &quot;, NULL);

	// Daten in test\[kuerzel]\ als .txt Datei abspeichern

	spath += kuerzel;
	spath += &quot;\\&quot;;
	spath += kuerzel;
	spath += &quot;.txt&quot;;
	save.open(spath.c_str(), ios::out|ios::trunc);
	if(save.is_open() != true){
		cout &lt;&lt; &quot;\nFehler beim oeffnen der Datei!\n\n&quot;;
		system(&quot;PAUSE&quot;);
		exit(1);
	}
	save &lt;&lt; &quot;Name: &quot; &lt;&lt; name &lt;&lt; endl
		 &lt;&lt; &quot;Alter: &quot; &lt;&lt; age &lt;&lt; endl
		 &lt;&lt; &quot;Funktion: &quot; &lt;&lt; funktion &lt;&lt; endl;
	save.close();
	cout &lt;&lt; &quot;\nDatei wurde erfolgreich erstellt\n\n&quot;;
	system(&quot;PAUSE&quot;);
	return 0;
}
</code></pre>
<p>Nur stelle ich jetzt fest, das ich überhaupt keinen Plan habe wie ich das mit CreateDirectory verwirklichen kann. Dazu muss ich sagen, ich habe mit CreateDirectory noch nie gearbeitet...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1971521</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1971521</guid><dc:creator><![CDATA[Blacky666]]></dc:creator><pubDate>Wed, 27 Oct 2010 14:52:41 GMT</pubDate></item><item><title><![CDATA[Reply to CreateDirectory Probleme on Wed, 27 Oct 2010 14:57:23 GMT]]></title><description><![CDATA[<p><a href="http://www.boost.org/doc/libs/1_44_0/libs/filesystem/v2/doc/index.htm" rel="nofollow">http://www.boost.org/doc/libs/1_44_0/libs/filesystem/v2/doc/index.htm</a></p>
<p>Schöner zu benutzen und vor allem Platformunabhängig.<br />
Kann ich nur empfehlen.<br />
rya.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1971524</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1971524</guid><dc:creator><![CDATA[[[global:former_user]]]]></dc:creator><pubDate>Wed, 27 Oct 2010 14:57:23 GMT</pubDate></item><item><title><![CDATA[Reply to CreateDirectory Probleme on Wed, 27 Oct 2010 15:11:02 GMT]]></title><description><![CDATA[<p>Und falls es doch nicht Boost sein soll, dann bist du im falschen Forum. <code>CreateDirectory</code> ist eine WinAPI Funktion. Wie man sie benutzt, steht alles in der <a href="http://msdn.microsoft.com/en-us/library/aa363855.aspx" rel="nofollow">Dokumentation</a>.</p>
<p>Grüssli</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1971535</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1971535</guid><dc:creator><![CDATA[Dravere]]></dc:creator><pubDate>Wed, 27 Oct 2010 15:11:02 GMT</pubDate></item><item><title><![CDATA[Reply to CreateDirectory Probleme on Wed, 27 Oct 2010 16:14:21 GMT]]></title><description><![CDATA[<p>Aber für so eine Mini-Funktionalität würde ich mir nicht den Brocken boost einbinden wollen.</p>
<p>Du kannst recht einfach prüfen, ob ein Ordner schon vorhanden ist:</p>
<pre><code class="language-cpp">typedef std::basic_string&lt;TCHAR&gt; string_type; // thx Unskilled

bool DirExists(const string_type&amp; name)
{
  WIN32_FIND_DATA data;
  HANDLE hdl=FindFirstFile(name.c_str(),&amp;data);
  if(hdl==INVALID_HANDLE_VALUE)
    return false;
  FindClose(hdl);
  return true; // es sollte egal sein, ob name eine Datei oder Verzeichnis ist 
}
</code></pre>
<p>Das Problem ist nun, dass CreateDirectory mit bspw. <code>d:\1\2\3</code> nur klappt, wenn <code>d:\1\2</code> schon vorhanden ist.<br />
Man kann sich deshalb so etwas zusammenschustern:</p>
<pre><code class="language-cpp">bool CreateDirectory(const string_type&amp; name)
{
  return(::CreateDirectory(name.c_str(),0)!=0);
}
bool CreatePath(const string_type&amp; name)
{
  if(CreateDirectory(name))
    return(true);
  size_t pos = name.rfind(TEXT(&quot;\\&quot;));
  if(pos!=string_type::npos)
  {
    if(!CreatePath(name.substr(0,pos)))
      return false;
    return(CreateDirectory(name));
  }
  return(false);
}
</code></pre>
<p>Es wird also rekursiv CreatePath aufgerufen, was bei der zu erwartenden geringen Anzahl kein Problem sein dürfte.<br />
Jetzt sollte Folgendes klappen:</p>
<pre><code class="language-cpp">bool CreateDir(const string_type&amp; name)
{
  if(!DirExists(name))
  {  if(!CreatePath(name))
       return false;
  }
  return true;
}
bool f()
{
  string_type str(&quot;d:\\&quot;);
  str+=&quot;1\\&quot;;
  str+=&quot;2\\&quot;;
  str+=&quot;3\\&quot;;
  str+=&quot;4\\&quot;;
  str+=&quot;5\\&quot;;
  str+=&quot;6&quot;;
  return CreateDir(str);
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1971581</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1971581</guid><dc:creator><![CDATA[Vicious Falcon]]></dc:creator><pubDate>Wed, 27 Oct 2010 16:14:21 GMT</pubDate></item><item><title><![CDATA[Reply to CreateDirectory Probleme on Wed, 27 Oct 2010 16:12:27 GMT]]></title><description><![CDATA[<p>Wieso Brocken?<br />
Es ist nur eine Library innerhalb des riesen Pakets. Und boost hat so gut wie jeder aufm Rechner der C++ programmiert^^.<br />
Und das sage ich als jemand der boost nur sehr selten empfiehlt. Aber in dem Fall zurecht.<br />
rya.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1971584</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1971584</guid><dc:creator><![CDATA[[[global:former_user]]]]></dc:creator><pubDate>Wed, 27 Oct 2010 16:12:27 GMT</pubDate></item><item><title><![CDATA[Reply to CreateDirectory Probleme on Wed, 27 Oct 2010 16:14:05 GMT]]></title><description><![CDATA[<p>Davon abgesehen das CreateDirectory nicht in das ANSI C++ Unterforum gehört, es gibt ein eigenes Unterforum für die WindowsAPI.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1971586</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1971586</guid><dc:creator><![CDATA[asc]]></dc:creator><pubDate>Wed, 27 Oct 2010 16:14:05 GMT</pubDate></item><item><title><![CDATA[Reply to CreateDirectory Probleme on Wed, 27 Oct 2010 19:12:12 GMT]]></title><description><![CDATA[<p>Blacky666 schrieb:</p>
<blockquote>
<pre><code class="language-cpp">// Abfrage ob der Ordner schon vorhanden ist
// ..
CreateDirectory(&quot; &quot;, NULL);
</code></pre>
<p>..ich habe mit CreateDirectory noch nie gearbeitet...</p>
</blockquote>
<p>Zwei ganz einfache Probleme.</p>
<p>Scorcher24 schrieb:</p>
<blockquote>
<p>&lt;Boostempfehlung&gt;rya.</p>
</blockquote>
<p>Okay, es ist nur eine kleine Bibiothek, aber sollte man sich, wenn man programmiert, nicht mit diesen einfachen Konzepten vertraut machen?</p>
<p>Dravere schrieb:</p>
<blockquote>
<p>.. <code>CreateDirectory</code> ist eine WinAPI Funktion. Wie man sie benutzt, steht alles in der <a href="http://msdn.microsoft.com/en-us/library/aa363855.aspx" rel="nofollow">Dokumentation</a>.</p>
</blockquote>
<p>Dass ein Link zur MSDN-Dokumentation nicht unbedingt zum Ziel führt, dürfte nach Codeansicht auch klar sein...</p>
<p>asc schrieb:</p>
<blockquote>
<p>Davon abgesehen das CreateDirectory nicht in das ANSI C++ Unterforum gehört, es gibt ein eigenes Unterforum für die WindowsAPI.</p>
</blockquote>
<p>Ja und jetzt?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1971689</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1971689</guid><dc:creator><![CDATA[Vicious Falcon]]></dc:creator><pubDate>Wed, 27 Oct 2010 19:12:12 GMT</pubDate></item><item><title><![CDATA[Reply to CreateDirectory Probleme on Fri, 29 Oct 2010 07:37:22 GMT]]></title><description><![CDATA[<p>Danke für euere Hilfe. Jetzt muss ich erstmal durch die ganzen Codes durcharbeiten, sodas ich diese erstmal richtig verstehe. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1972221</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1972221</guid><dc:creator><![CDATA[Blacky666]]></dc:creator><pubDate>Fri, 29 Oct 2010 07:37:22 GMT</pubDate></item></channel></rss>