<?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[Shell mit aktueller Pfadangabe...]]></title><description><![CDATA[<p>Hallo Leute, ich möchte erstmal eine Shell erstellen mit eigenen Befehlen, die sich wie cmd oder bash verhält, also am Anfang der Prompt soll die aktuelle Pfadangabe stehen.<br />
Also ich starte z.B. die shell in <strong>c:\test</strong>, gleichzeitig soll der shell der pfad übermittelt werden z.b. so:</p>
<p><strong>C:\test&gt;&gt;</strong></p>
<p>doch das nächste problem ist, wie kann ich dann verzeichnisse wechseln?</p>
<p><strong>C:\test\help&gt;&gt;</strong></p>
]]></description><link>https://www.c-plusplus.net/forum/topic/167188/shell-mit-aktueller-pfadangabe</link><generator>RSS for Node</generator><lastBuildDate>Thu, 16 Jul 2026 14:10:50 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/167188.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 07 Dec 2006 16:45:21 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Shell mit aktueller Pfadangabe... on Thu, 07 Dec 2006 16:45:21 GMT]]></title><description><![CDATA[<p>Hallo Leute, ich möchte erstmal eine Shell erstellen mit eigenen Befehlen, die sich wie cmd oder bash verhält, also am Anfang der Prompt soll die aktuelle Pfadangabe stehen.<br />
Also ich starte z.B. die shell in <strong>c:\test</strong>, gleichzeitig soll der shell der pfad übermittelt werden z.b. so:</p>
<p><strong>C:\test&gt;&gt;</strong></p>
<p>doch das nächste problem ist, wie kann ich dann verzeichnisse wechseln?</p>
<p><strong>C:\test\help&gt;&gt;</strong></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1188480</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1188480</guid><dc:creator><![CDATA[kernel64]]></dc:creator><pubDate>Thu, 07 Dec 2006 16:45:21 GMT</pubDate></item><item><title><![CDATA[Reply to Shell mit aktueller Pfadangabe... on Sat, 09 Dec 2006 17:15:37 GMT]]></title><description><![CDATA[<p>Ich weiß nicht genau was Du meinst -ist n bisschen wirsch beschrieben- aber meisnt Du &gt;&gt; <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/getmodulefilename.asp" rel="nofollow">GetModuleFileName</a></p>
<p>Vielleicht in diesem Kontext noch hilfreich ist:<br />
<a href="http://msdn.microsoft.com/library/en-us/dllproc/base/getmodulehandle.asp" rel="nofollow">GetModuleHandle()</a></p>
<p>Damit kannst Du Dir den Pfad Deiner Executeable holen und einfach ein '&gt;&gt;' anhängen. Die Befehle musst Du natürlich in Strings parsen (Wenn das überhaupt zu Deiner Frage gehörte <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f921.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--clown_face"
      title=":clown:"
      alt="🤡"
    /> ).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1189153</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1189153</guid><dc:creator><![CDATA[CodeFinder]]></dc:creator><pubDate>Sat, 09 Dec 2006 17:15:37 GMT</pubDate></item><item><title><![CDATA[Reply to Shell mit aktueller Pfadangabe... on Sat, 09 Dec 2006 17:42:38 GMT]]></title><description><![CDATA[<p>Die Shell ist eine Applikationwie jede andere. Auch sie hat ein working directory. Die Funktionen dafür sind GetCurrentDirectory, SetCurrentDirectory.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1189178</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1189178</guid><dc:creator><![CDATA[Martin Richter]]></dc:creator><pubDate>Sat, 09 Dec 2006 17:42:38 GMT</pubDate></item><item><title><![CDATA[Reply to Shell mit aktueller Pfadangabe... on Sat, 09 Dec 2006 17:54:33 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/35992">@Martin</a> Richter: Hab das so verstanden, dass er sich ne eigene Shell schreiben wollte und dann den Pfad zu seine Shell (eben seine Applikation) übergeben wollte...Naja wir werden es ja sehen :xmas2: .</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1189192</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1189192</guid><dc:creator><![CDATA[CodeFinder]]></dc:creator><pubDate>Sat, 09 Dec 2006 17:54:33 GMT</pubDate></item><item><title><![CDATA[Reply to Shell mit aktueller Pfadangabe... on Sat, 09 Dec 2006 21:24:33 GMT]]></title><description><![CDATA[<p>Damit ich in einem bestimmten Verzeichnis arbeiten kann, muss ich erstmal dahinkommen, z.B. möchte ich in <strong>c:\test\datei.txt</strong> die Datei lesen. Die Shell wird hier in c:\ gestartet, also in der Promp steht <strong>c:\&gt;&gt;</strong> jetzt mit einem Befehl wie z.b <strong>cd</strong> in das verzeichnis wechseln.<br />
ICh möchte nur der Shell mit sagen in welchem Verzechnis sie gerade arbeiten soll, um z.b. dateien lesen,schreiben,.... so wie <strong>cmd</strong></p>
<p>Mein eigenes Verzeichnis bekomme ich mit folgender Funktion:</p>
<pre><code class="language-cpp">string ApplicationDirectory()
{
	TCHAR szPathName[_MAX_PATH];
	::GetModuleFileName(NULL, szPathName, _MAX_PATH);
	LPTSTR pszFileName = _tcsrchr(szPathName, '\\') + 1;
	*pszFileName = '\0'; 

	return szPathName;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1189258</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1189258</guid><dc:creator><![CDATA[kernel64]]></dc:creator><pubDate>Sat, 09 Dec 2006 21:24:33 GMT</pubDate></item><item><title><![CDATA[Reply to Shell mit aktueller Pfadangabe... on Sat, 09 Dec 2006 22:09:50 GMT]]></title><description><![CDATA[<p>Dann verwende SetCurrentDirectory und Du kannst direkt mit fopen, die Datei öffnen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1189272</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1189272</guid><dc:creator><![CDATA[Martin Richter]]></dc:creator><pubDate>Sat, 09 Dec 2006 22:09:50 GMT</pubDate></item><item><title><![CDATA[Reply to Shell mit aktueller Pfadangabe... on Sun, 10 Dec 2006 10:16:41 GMT]]></title><description><![CDATA[<p>Hab folgendes zusammengebastelt:</p>
<pre><code class="language-cpp">#include &lt;windows.h&gt;
#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;tchar.h&gt;

using namespace std;

string ApplicationDirectory();

//***Global***
string Pfad = ApplicationDirectory();

void prompt()
{	
	cout &lt;&lt; Pfad &lt;&lt; &quot;&gt;&gt;&quot;;
}

string ApplicationDirectory()
{
	TCHAR szPathName[_MAX_PATH];
	::GetModuleFileName(NULL, szPathName, _MAX_PATH);
	LPTSTR pszFileName = _tcsrchr(szPathName, '\\') + 1;
	*pszFileName = '\0'; 

	return szPathName;
}

int main()
{
	string str;
	do
	{
		prompt();
		getline(cin, str);		

		//Mit Befehl cd ... in ein anderes Verzechnis wechseln

	}while(1);
	return 0;
}
</code></pre>
<p>Anfangs wird in der Prompt der Start Pfad der Programms ausgegeben, dieser befindet sich in der Variable <strong>Pfad</strong>.<br />
Solbald ich den befehl <strong>cd VERZEICHNIS</strong> eingebe, wird VERZEICHNIS in <strong>Pfad</strong> gespeichert.</p>
<p>Wie soll ich das mit SetCurrentDirectory machen so in etwa -&gt; SetCurrentDirectory(VERZEICHNIS) ??<br />
Und wenn ich dann den Befehl <strong>dir</strong> eingebe wird nur das aktuelle Verzeichnis in dem das Programm gestartet wurde ausgegeben und nicht das geänderte.</p>
<p>Bitte um Hilfe</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1189375</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1189375</guid><dc:creator><![CDATA[kernel64]]></dc:creator><pubDate>Sun, 10 Dec 2006 10:16:41 GMT</pubDate></item><item><title><![CDATA[Reply to Shell mit aktueller Pfadangabe... on Tue, 12 Dec 2006 09:16:47 GMT]]></title><description><![CDATA[<p>Also ich will noch einmal fragen, wie kann ich die den meiner shell mitteilen das sie sich in einem anderen pfad befindet, ich weiß nicht wie man das mit <strong>SetCurrentDirectory()</strong> verwendet.<br />
Ich hoffe ihr versteht mich, also meine shell soll so funktionsweise wie cmd.exe, so dass ich in einem belibiegen Verzeichnis arbeiten kann.</p>
<p>Bitte um Hilfe</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1190433</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1190433</guid><dc:creator><![CDATA[kernel64]]></dc:creator><pubDate>Tue, 12 Dec 2006 09:16:47 GMT</pubDate></item><item><title><![CDATA[Reply to Shell mit aktueller Pfadangabe... on Tue, 12 Dec 2006 09:26:38 GMT]]></title><description><![CDATA[<p>Ja! Deine Applikation befindet sich in diesem Verzeichnis, das GetCurrentDirectory angibt. Alle Dateioperationen die keinen Pfad haben oder einen relativen Pfad haben beziehen sich auf dieses directory. Mie Set setzen mit Get lesen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1190439</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1190439</guid><dc:creator><![CDATA[Martin Richter]]></dc:creator><pubDate>Tue, 12 Dec 2006 09:26:38 GMT</pubDate></item><item><title><![CDATA[Reply to Shell mit aktueller Pfadangabe... on Tue, 12 Dec 2006 22:41:16 GMT]]></title><description><![CDATA[<p>Hab folgendes zusammengebastelt:</p>
<pre><code class="language-cpp">#include &lt;windows.h&gt;
#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;tchar.h&gt;
#include &lt;sstream&gt;
#include &lt;vector&gt;

using namespace std;

string ApplicationDirectory();

//***Global***
string Pfad = ApplicationDirectory();

string ApplicationDirectory()
{
	TCHAR szPathName[_MAX_PATH];
	::GetModuleFileName(NULL, szPathName, _MAX_PATH);
	LPTSTR pszFileName = _tcsrchr(szPathName, '\\') + 1;
	*pszFileName = '\0'; 

	return szPathName;
}

//Ausgabe Prompt
void prompt()
{	
	cout &lt;&lt; Pfad &lt;&lt; &quot;&gt;&gt;&quot;;
}

int main()
{
	string str;
	do
	{
		//Setzt den aktuellen Pfad
		SetCurrentDirectory(Pfad.c_str());
		prompt();

		getline(cin, str);	

		istringstream cmdline (str);
		string input;
		vector&lt;string&gt; params;

		string tmp;
		while (cmdline &gt;&gt; tmp) 
		{
			params.push_back (tmp);
		}

		if(params.size() &gt;= 2)
		{
			if(params[0] == &quot;cd&quot;)
			{
				cout &lt;&lt; &quot;Wechsel zu -&gt; &quot; &lt;&lt; params[1] &lt;&lt; endl;
				Pfad = params[1];
			}
		}
		if(params.size() &gt;= 1)
		{
			if(params[0] == &quot;exit&quot;)
				return 0;
			if(params[0] == &quot;dir&quot;)
				system(&quot;dir&quot;);

		}

	}while(1);
	return 0;
}
</code></pre>
<p>Es funktioniert jetzt, gibt es aber noch Verbesserungsvorschläge und wie kann ich prüfen ob der Pfad bei cd auch existiert</p>
<p>Beispiel:</p>
<p>*<em>cd x:*</em> // Fehler x existiert nicht!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1190921</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1190921</guid><dc:creator><![CDATA[kernel64]]></dc:creator><pubDate>Tue, 12 Dec 2006 22:41:16 GMT</pubDate></item><item><title><![CDATA[Reply to Shell mit aktueller Pfadangabe... on Wed, 13 Dec 2006 07:15:58 GMT]]></title><description><![CDATA[<p>PathIsDirectory</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1190983</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1190983</guid><dc:creator><![CDATA[Martin Richter]]></dc:creator><pubDate>Wed, 13 Dec 2006 07:15:58 GMT</pubDate></item><item><title><![CDATA[Reply to Shell mit aktueller Pfadangabe... on Thu, 14 Dec 2006 13:37:48 GMT]]></title><description><![CDATA[<p>Das mit der Überprüfung funktioniert jetzt <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="🙂"
    /><br />
Hab da ein nächstes Problem(e), wenn ich mich z.B. im Verzeichnis c:\ befinde wird auch in der Prompt c:\ angezeigt, doch wenn ich dann in ein weiteres Unterverzeichnis wechseln will wie z.B. Windows dann wird in der Prompt nur Windows angezeigt und nicht der volle Pfad: *<em>c:\windows*</em><br />
Die Shell weiß das sie sich im verzeichnis c:\windows befindet, nur der Prompt muss ich dies noch irgendwie mitteilen. Ich dachte mir wenn ich das neue Unterverzeichnis dem string Pfad dazuaddiere, also <strong>pfad += params[1]</strong> dann würde der ganze Pfad stimmen doch das problem ist wenn ich in ein andere Partition wechseln will wie x: dann sehe der string so aus:</p>
<p>Pfad = c:\windows\x:\... //es wird immer dann was dazu addiert.</p>
<p>Wie würdet ihr das lösen??</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1191774</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1191774</guid><dc:creator><![CDATA[kernel64]]></dc:creator><pubDate>Thu, 14 Dec 2006 13:37:48 GMT</pubDate></item><item><title><![CDATA[Reply to Shell mit aktueller Pfadangabe... on Sun, 17 Dec 2006 21:04:53 GMT]]></title><description><![CDATA[<p>Hier nochmal mein überarbeiteter Code:</p>
<pre><code class="language-cpp">#include &lt;windows.h&gt;
#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;tchar.h&gt;
#include &lt;sstream&gt;
#include &lt;vector&gt;
#include &lt;Shlwapi.h&gt;

using namespace std;

#pragma comment(lib, &quot;Shlwapi.lib&quot;)

string ApplicationDirectory();

//***Global***
string Pfad = ApplicationDirectory();

string ApplicationDirectory()
{
	TCHAR szPathName[_MAX_PATH];
	::GetModuleFileName(NULL, szPathName, _MAX_PATH);
	LPTSTR pszFileName = _tcsrchr(szPathName, '\\') + 1;
	*pszFileName = '\0'; 

	return szPathName;
}

int checkDir(string str)
{
	if (PathIsDirectory(str.c_str()))
		return 1;
	else
		return 0;
}

//Ausgabe Prompt
void prompt()
{	
	cout &lt;&lt; Pfad &lt;&lt; &quot;&gt;&gt;&quot;;
}

int main()
{
	string str;
	do
	{
		//Setzt den aktuellen Pfad
		SetCurrentDirectory(Pfad.c_str());
		prompt();

		getline(cin, str);	

		istringstream cmdline (str);
		string input;
		vector&lt;string&gt; params;

		string tmp;
		while (cmdline &gt;&gt; tmp) 
		{
			params.push_back (tmp);
		}

		if(params.size() &gt;= 2)
		{
			if(params[0] == &quot;cd&quot;)
			{				
				//Pfad = params[1];
				if(checkDir(params[1]) == 1)
				{
					Pfad = params[1];
				}
				else
					cout &lt;&lt; &quot;Verzeichnis '&quot; &lt;&lt; params[1] &lt;&lt; &quot;' nicht gefunden&quot; &lt;&lt; endl &lt;&lt; endl;

			}
		}
		if(params.size() &gt;= 1)
		{
			if(params[0] == &quot;exit&quot;)
				return 0;
			if(params[0] == &quot;dir&quot;)
				system(&quot;dir&quot;);

		}

	}while(1);
	return 0;
}
</code></pre>
<p>Ich hoffe Ihr könnt mir helfen, das Programm startet dort wo es kopiert wurde z.B. *<em>F:\test*</em> jetzt möchte ich in nach *<em>c:*</em> wechseln, gebe hierfür *<em>cd c:*</em> ein. In der Prompt steht jetzt <strong>c:\&gt;&gt;</strong> anschließend möchte ich in das Windows verzeihnis wechseln und gebe hierfür <strong>cd windows</strong> ein, jetzt steht in der Prompt <strong>windows&gt;&gt;</strong> doch wie kann man den ganzen Pfad ausgeben, hier <strong>c:\windows&gt;&gt;</strong></p>
<p>Bitte um Hilfe!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1193698</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1193698</guid><dc:creator><![CDATA[kernel64]]></dc:creator><pubDate>Sun, 17 Dec 2006 21:04:53 GMT</pubDate></item><item><title><![CDATA[Reply to Shell mit aktueller Pfadangabe... on Sun, 17 Dec 2006 21:28:40 GMT]]></title><description><![CDATA[<p>GetCurrentDirectory!?<br />
GetFullPathName !?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1193706</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1193706</guid><dc:creator><![CDATA[Jochen Kalmbach]]></dc:creator><pubDate>Sun, 17 Dec 2006 21:28:40 GMT</pubDate></item><item><title><![CDATA[Reply to Shell mit aktueller Pfadangabe... on Sun, 17 Dec 2006 21:44:55 GMT]]></title><description><![CDATA[<p>Vielen Dank <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="🙂"
    /><br />
Noch ein kurze Frage, wie kann man das folgende verbessern damit das feld keine feste größe hat, damit es zu keinem Bufferoverflow kommt.</p>
<pre><code class="language-cpp">char app_name[300]; 
GetCurrentDirectory(300, LPWSTR(app_name)); // aktuelles Verzeichnis holen...
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1193717</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1193717</guid><dc:creator><![CDATA[kernel64]]></dc:creator><pubDate>Sun, 17 Dec 2006 21:44:55 GMT</pubDate></item><item><title><![CDATA[Reply to Shell mit aktueller Pfadangabe... on Sun, 17 Dec 2006 21:55:00 GMT]]></title><description><![CDATA[<p>Doku lesen</p>
<blockquote>
<p>To determine the required buffer size, set this parameter to NULL and the nBufferLength parameter to 0.</p>
</blockquote>
<p>und dann:</p>
<pre><code class="language-cpp">DWORD dwReqSize = GetCurrentDirectory(0, NULL);
TCHAR szCurDir = new TCHAR[dwReqSize+1];
GetCurrentDirectory(dwReqSize+1, szCurDir);
// ....
delete [] szCurDir;
</code></pre>
<p>PS: Warum castest Du ein &quot;char&quot; nach &quot;LPWSTR&quot;????? Das geht auf jeden Fall schief!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1193721</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1193721</guid><dc:creator><![CDATA[Jochen Kalmbach]]></dc:creator><pubDate>Sun, 17 Dec 2006 21:55:00 GMT</pubDate></item><item><title><![CDATA[Reply to Shell mit aktueller Pfadangabe... on Sun, 17 Dec 2006 22:02:32 GMT]]></title><description><![CDATA[<p>Hab mit deinem Beispiel 3 Fehler:</p>
<pre><code>error C2440: 'Initialisierung': 'TCHAR *' kann nicht in 'TCHAR' konvertiert werden
        Es gibt keinen Kontext, in dem diese Konvertierung möglich ist

error C2664: 'GetCurrentDirectoryA': Konvertierung des Parameters 2 von 'TCHAR' in 'LPSTR' nicht möglich

error C2541: 'delete': Objekte, die keine Zeiger sind, können nicht gelöscht werden
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1193725</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1193725</guid><dc:creator><![CDATA[kernel64]]></dc:creator><pubDate>Sun, 17 Dec 2006 22:02:32 GMT</pubDate></item><item><title><![CDATA[Reply to Shell mit aktueller Pfadangabe... on Sun, 17 Dec 2006 22:04:07 GMT]]></title><description><![CDATA[<p>Sollte natürlich</p>
<pre><code class="language-cpp">TCHAR *szCurDir = new TCHAR[dwReqSize+1];
</code></pre>
<p>heissen...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1193726</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1193726</guid><dc:creator><![CDATA[Jochen Kalmbach]]></dc:creator><pubDate>Sun, 17 Dec 2006 22:04:07 GMT</pubDate></item><item><title><![CDATA[Reply to Shell mit aktueller Pfadangabe... on Sun, 17 Dec 2006 22:05:46 GMT]]></title><description><![CDATA[<p>Vielen Dank <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/1193728</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1193728</guid><dc:creator><![CDATA[kernel64]]></dc:creator><pubDate>Sun, 17 Dec 2006 22:05:46 GMT</pubDate></item></channel></rss>