<?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[Datei im Binäry-Modi öffnen, Inhalt auslesen und dann kopieren.]]></title><description><![CDATA[<p>Hallo alle zusammen!</p>
<p>Ich habe wieder mal ein Problem. Ich möchte ein Datei kopieren</p>
<p>Die Datei muss hierzu im Binary-Mode geöffnet, der Inhalt ausgelesen und dann kopiert werden.</p>
<p>Bisher habe ich versucht:</p>
<pre><code class="language-cpp">DateiKopieren(char quelle[], char ziel[])
{
ifstream infile(quelle, ios::binary);

	if(infile.good())
	{
		AnsiString S = ziel + ExtractFileName(AnsiString(quelle));
		int i = DateGroesseErmitteln(AnsiString(quelle));

		ofstream outfile(S.c_str(), ios::binary);

		if(outfile.good())
			outfile.write((char*)&amp;infile, i);

		ShowMessage(&quot;Öffnen gelungen&quot;);

	outfile.close();
	}
}
</code></pre>
<p>Mir fehlt ein fstream Buffer wo ich den Inhalt erst einlesen kann!<br />
Hat jemand ein Idee?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/244201/datei-im-binäry-modi-öffnen-inhalt-auslesen-und-dann-kopieren</link><generator>RSS for Node</generator><lastBuildDate>Sat, 04 Apr 2026 00:16:12 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/244201.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 26 Jun 2009 15:52:38 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Datei im Binäry-Modi öffnen, Inhalt auslesen und dann kopieren. on Fri, 26 Jun 2009 15:53:02 GMT]]></title><description><![CDATA[<p>Hallo alle zusammen!</p>
<p>Ich habe wieder mal ein Problem. Ich möchte ein Datei kopieren</p>
<p>Die Datei muss hierzu im Binary-Mode geöffnet, der Inhalt ausgelesen und dann kopiert werden.</p>
<p>Bisher habe ich versucht:</p>
<pre><code class="language-cpp">DateiKopieren(char quelle[], char ziel[])
{
ifstream infile(quelle, ios::binary);

	if(infile.good())
	{
		AnsiString S = ziel + ExtractFileName(AnsiString(quelle));
		int i = DateGroesseErmitteln(AnsiString(quelle));

		ofstream outfile(S.c_str(), ios::binary);

		if(outfile.good())
			outfile.write((char*)&amp;infile, i);

		ShowMessage(&quot;Öffnen gelungen&quot;);

	outfile.close();
	}
}
</code></pre>
<p>Mir fehlt ein fstream Buffer wo ich den Inhalt erst einlesen kann!<br />
Hat jemand ein Idee?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1733395</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1733395</guid><dc:creator><![CDATA[aesse]]></dc:creator><pubDate>Fri, 26 Jun 2009 15:53:02 GMT</pubDate></item><item><title><![CDATA[Reply to Datei im Binäry-Modi öffnen, Inhalt auslesen und dann kopieren. on Fri, 26 Jun 2009 16:26:14 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">if(OpenDialog1-&gt;Execute())
   {
      SaveDialog1-&gt;Execute();
      ifstream in(OpenDialog1-&gt;FileName.c_str(),ios_base::in | ios_base::binary);
      ofstream out(SaveDialog1-&gt;FileName.c_str(),ios_base::out | ios_base::binary);
      out &lt;&lt; in.rdbuf();
      out.close();
      in.close();
   }
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1733406</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1733406</guid><dc:creator><![CDATA[streamer]]></dc:creator><pubDate>Fri, 26 Jun 2009 16:26:14 GMT</pubDate></item><item><title><![CDATA[Reply to Datei im Binäry-Modi öffnen, Inhalt auslesen und dann kopieren. on Fri, 26 Jun 2009 17:25:44 GMT]]></title><description><![CDATA[<p>Danke für den Code,</p>
<p>ich dachte dass mit diese Vorgehensweise könnte man auch die geöffnete Dateien (bzw. *.pst) kopieren, das ist leider nicht der Fall, obwohl unter VisualBasic sollte es auf diese Weise gehen:<br />
<a href="http://www.vbarchiv.net/tipps/details.php?id=783" rel="nofollow">http://www.vbarchiv.net/tipps/details.php?id=783</a></p>
<p>Ich denke es muss auch unter C++ möglich sein die geöffnete Dateien zu kopieren.<br />
Die Frage ist mit welcher Methode?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1733425</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1733425</guid><dc:creator><![CDATA[aesse]]></dc:creator><pubDate>Fri, 26 Jun 2009 17:25:44 GMT</pubDate></item><item><title><![CDATA[Reply to Datei im Binäry-Modi öffnen, Inhalt auslesen und dann kopieren. on Fri, 26 Jun 2009 18:40:30 GMT]]></title><description><![CDATA[<p>Du kannst dann mit</p>
<pre><code class="language-cpp">in.seekg(ios::beg);
</code></pre>
<p>wieder zurücksetzen</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1733463</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1733463</guid><dc:creator><![CDATA[streamer]]></dc:creator><pubDate>Fri, 26 Jun 2009 18:40:30 GMT</pubDate></item><item><title><![CDATA[Reply to Datei im Binäry-Modi öffnen, Inhalt auslesen und dann kopieren. on Fri, 26 Jun 2009 19:28:14 GMT]]></title><description><![CDATA[<p>An welcher stelle?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1733476</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1733476</guid><dc:creator><![CDATA[aesse]]></dc:creator><pubDate>Fri, 26 Jun 2009 19:28:14 GMT</pubDate></item><item><title><![CDATA[Reply to Datei im Binäry-Modi öffnen, Inhalt auslesen und dann kopieren. on Fri, 26 Jun 2009 20:16:34 GMT]]></title><description><![CDATA[<p>Sorry, schon so lange her ... an den Anfang</p>
<pre><code class="language-cpp">in.clear();
in.seekg (0L, ios::beg);
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1733499</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1733499</guid><dc:creator><![CDATA[streamer]]></dc:creator><pubDate>Fri, 26 Jun 2009 20:16:34 GMT</pubDate></item><item><title><![CDATA[Reply to Datei im Binäry-Modi öffnen, Inhalt auslesen und dann kopieren. on Sat, 27 Jun 2009 07:27:23 GMT]]></title><description><![CDATA[<p>Ich habe folgendes:</p>
<pre><code class="language-cpp">char quelle[];
char ziel[];
AnsiString zS;
if(strlen(ziel) &lt;= 3)
  /* AnsiString */zS = ziel + ExtractFileName(AnsiString(quelle));
else
    zS = AnsiString(ziel) + &quot;\\&quot;+ ExtractFileName(AnsiString(quelle));

ifstream in(quelle,ios_base::in | ios_base::binary);
in.clear();
in.seekg (0L, ios::beg);
ofstream out(zS.c_str(),ios_base::out | ios_base::binary);
out &lt;&lt; in.rdbuf();
out.close();
in.close();
</code></pre>
<p>Ergebnis nach wie vor, negativ!</p>
<p>Sorry ich habe zS doppelt deklariert gehabt! 27.06.09</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1733523</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1733523</guid><dc:creator><![CDATA[aesse]]></dc:creator><pubDate>Sat, 27 Jun 2009 07:27:23 GMT</pubDate></item><item><title><![CDATA[Reply to Datei im Binäry-Modi öffnen, Inhalt auslesen und dann kopieren. on Fri, 26 Jun 2009 21:10:23 GMT]]></title><description><![CDATA[<p>Also wenn das alles an Code ist, dann fällt natürlich erstmal auf, das der Quelldateiname fehlt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1733528</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1733528</guid><dc:creator><![CDATA[streamer]]></dc:creator><pubDate>Fri, 26 Jun 2009 21:10:23 GMT</pubDate></item><item><title><![CDATA[Reply to Datei im Binäry-Modi öffnen, Inhalt auslesen und dann kopieren. on Sat, 27 Jun 2009 07:31:29 GMT]]></title><description><![CDATA[<p>Guten morgen,</p>
<p>Der Quelldateiname ist &quot;quelle[]&quot;.<br />
Also volständig siet so aus:</p>
<pre><code class="language-cpp">void __fastcall TForm1::OffeneDateiKopieren(char quelle[], char ziel[])
{
	AnsiString zS;
	if(strlen(ziel) &lt;= 3)
		zS = ziel + ExtractFileName(AnsiString(quelle));
	else
		zS = AnsiString(ziel) + &quot;\\&quot;+ ExtractFileName(AnsiString(quelle));

	ifstream in(quelle,ios_base::in | ios_base::binary);
	in.clear();
	in.seekg (0L, ios::beg);
	ofstream out(zS.c_str(),ios_base::out | ios_base::binary);
	out &lt;&lt; in.rdbuf();
	out.close();
	in.close();
}
//---------------------------------------------------------------------------
</code></pre>
<p>Aufruf:</p>
<pre><code class="language-cpp">OffeneDateiKopieren(Edit1-&gt;Text.c_str(), Edit2-&gt;Text.c_str());
</code></pre>
<p>Wo Edit1-Text voller qualfizierter Pfad der Quelldatei vom OpenDialog und<br />
Edit2-&gt;Text der Pfad des Ordners von BrowseForFolder ist.</p>
<p>Bei dem Kopieren wird die Zieldatei richtig angelegt, nur inhalt bleibt dann Null Bytes (wenn die Queldatei geöffnet ist).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1733571</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1733571</guid><dc:creator><![CDATA[aesse]]></dc:creator><pubDate>Sat, 27 Jun 2009 07:31:29 GMT</pubDate></item><item><title><![CDATA[Reply to Datei im Binäry-Modi öffnen, Inhalt auslesen und dann kopieren. on Sat, 27 Jun 2009 09:10:46 GMT]]></title><description><![CDATA[<p>Entweder</p>
<pre><code class="language-cpp">OffeneDateiKopieren(char *quelle, char *ziel)
</code></pre>
<p>oder</p>
<pre><code class="language-cpp">OffeneDateiKopieren(String quelle, String ziel)
</code></pre>
<p>oder besser fürs Kopieren gleich</p>
<p>CopyFile<br />
oder CopyFileTo</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1733585</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1733585</guid><dc:creator><![CDATA[streamer]]></dc:creator><pubDate>Sat, 27 Jun 2009 09:10:46 GMT</pubDate></item><item><title><![CDATA[Reply to Datei im Binäry-Modi öffnen, Inhalt auslesen und dann kopieren. on Sat, 27 Jun 2009 15:21:56 GMT]]></title><description><![CDATA[<p>Hallo streamer!</p>
<p>Danke für deine Vorschläge.<br />
Der Sinn und Zweck Benutzung der Kalsse fstream ist um die geöffnete Dateien zu kopieren zu können. Natürlich kann man auch so schreiben wie Du vorschlägst, aber Ergebnis bleibt unverändert.<br />
Methoden CopyFile() und CopyFileTo() kopiert keine geöffnete (<em>.pst) oder (</em>.gdb) Dateien, viele andere -&gt; Word ,Excel, PDF, .... schon.</p>
<p>Darum das Problem bleibt nach wie vor offen. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1733731</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1733731</guid><dc:creator><![CDATA[aesse]]></dc:creator><pubDate>Sat, 27 Jun 2009 15:21:56 GMT</pubDate></item><item><title><![CDATA[Reply to Datei im Binäry-Modi öffnen, Inhalt auslesen und dann kopieren. on Sat, 27 Jun 2009 20:43:01 GMT]]></title><description><![CDATA[<p>wie wärs damit?</p>
<pre><code class="language-cpp">fstream in, out;
in.open(datei1,ios::in|ios::binary);
out.open(datei2,ios::out|ios::binary);
unsigned char c;

while(1)
{
   in &gt;&gt; c;
   if(in.eof())
      break;
   out.put(c);
}
in.close();
out.close();
</code></pre>
<p>greetz KN4CK3R</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1733819</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1733819</guid><dc:creator><![CDATA[KN4CK3R]]></dc:creator><pubDate>Sat, 27 Jun 2009 20:43:01 GMT</pubDate></item><item><title><![CDATA[Reply to Datei im Binäry-Modi öffnen, Inhalt auslesen und dann kopieren. on Mon, 29 Jun 2009 08:14:42 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>leider das Ergebnis auch mit diesem Versuch ist negativ.<br />
Danke trotzdem!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1734395</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1734395</guid><dc:creator><![CDATA[aesse]]></dc:creator><pubDate>Mon, 29 Jun 2009 08:14:42 GMT</pubDate></item><item><title><![CDATA[Reply to Datei im Binäry-Modi öffnen, Inhalt auslesen und dann kopieren. on Mon, 29 Jun 2009 08:47:45 GMT]]></title><description><![CDATA[<p>Hallo</p>
<p>std::stream dürfte dir da kaum weiterhelfen. Denn die Sperre wird nicht von einer Funktion der C++ Schicht verursacht, sondern von Windows. Du wirst diese Sperre, wenn überhaupt möglich, auch nur mit Windows-Mitteln umgehen können.</p>
<p>bis bald<br />
akari</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1734407</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1734407</guid><dc:creator><![CDATA[akari]]></dc:creator><pubDate>Mon, 29 Jun 2009 08:47:45 GMT</pubDate></item><item><title><![CDATA[Reply to Datei im Binäry-Modi öffnen, Inhalt auslesen und dann kopieren. on Mon, 29 Jun 2009 08:48:00 GMT]]></title><description><![CDATA[<p>Dieser Thread wurde von Moderator/in <a href="http://www.c-plusplus.net/forum/profile-var-mode-is-viewprofile-and-u-is-14774.html" rel="nofollow">akari</a> aus dem Forum <a href="http://www.c-plusplus.net/forum/viewforum-var-f-is-2.html" rel="nofollow">VCL (C++ Builder)</a> in das Forum <a href="http://www.c-plusplus.net/forum/viewforum-var-f-is-4.html" rel="nofollow">WinAPI</a> verschoben.</p>
<p>Im Zweifelsfall bitte auch folgende Hinweise beachten:<br />
<a href="http://www.c-plusplus.net/forum/viewtopic-var-t-is-39405.html" rel="nofollow">C/C++ Forum :: FAQ - Sonstiges :: Wohin mit meiner Frage?</a></p>
<p><em>Dieses Posting wurde automatisch erzeugt.</em></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1734408</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1734408</guid><dc:creator><![CDATA[C++ Forumbot]]></dc:creator><pubDate>Mon, 29 Jun 2009 08:48:00 GMT</pubDate></item><item><title><![CDATA[Reply to Datei im Binäry-Modi öffnen, Inhalt auslesen und dann kopieren. on Mon, 29 Jun 2009 10:03:12 GMT]]></title><description><![CDATA[<p>Hallo alle zusammen,</p>
<p>kann mir jemànd helfen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1734452</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1734452</guid><dc:creator><![CDATA[aesse]]></dc:creator><pubDate>Mon, 29 Jun 2009 10:03:12 GMT</pubDate></item><item><title><![CDATA[Reply to Datei im Binäry-Modi öffnen, Inhalt auslesen und dann kopieren. on Mon, 29 Jun 2009 11:33:06 GMT]]></title><description><![CDATA[<p>Das Problem wird wohl sein, in welchem Modus der Besitzer der Datei die Datei geöffnet hält. Wenn er absichtlich keinen shared Zugriff erlaubt geht´s einfach nicht, da hilft dir keine Funktion der WinAPI weiter. Du kannst diesen Schnipsel mal ausprobieren, der kann zumindest geöffnete Dateien kopieren, wenn der Besitzer Lesezugriffe erlaubt. Die Unterverzeichnisstruktur musst du ggf. selbst erzeugen, d.h. der Verzeichnisbaum muss bereits existieren.</p>
<pre><code class="language-cpp">#include &lt;string&gt;
#include &lt;vector&gt;

#include &lt;windows.h&gt;

using namespace std;

void copy_file( const string&amp; source, const string&amp; target )
{
	HANDLE hSource = ::CreateFile( source.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL|FILE_FLAG_BACKUP_SEMANTICS, NULL );
	if( INVALID_HANDLE_VALUE == hSource )
	{
		return;
	}
	HANDLE hTarget = ::CreateFile( target.c_str(), GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
	if( INVALID_HANDLE_VALUE == hTarget )
	{
		::CloseHandle( hSource );
		return;
	}
	const unsigned int BufferSize = 256 * 1024;
	vector&lt;char&gt; Buffer( BufferSize );
	DWORD dwReadCount = 0;
	DWORD dwWriteCount= 0;
	if( ::ReadFile( hSource, &amp;Buffer[0], BufferSize, &amp;dwReadCount, NULL ) )
	{
		while( dwReadCount != 0 )
		{
			::WriteFile( hTarget, &amp;Buffer[0], dwReadCount, &amp;dwWriteCount, NULL );
			::ReadFile( hSource, &amp;Buffer[0], BufferSize, &amp;dwReadCount, NULL );
		}
	}
	::CloseHandle( hSource );
	::CloseHandle( hTarget );
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1734486</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1734486</guid><dc:creator><![CDATA[DocShoe]]></dc:creator><pubDate>Mon, 29 Jun 2009 11:33:06 GMT</pubDate></item><item><title><![CDATA[Reply to Datei im Binäry-Modi öffnen, Inhalt auslesen und dann kopieren. on Mon, 29 Jun 2009 12:46:45 GMT]]></title><description><![CDATA[<p>Ab WindowsXP kann man geöffnete Dateien über den Volume Shadow Copy Service öffnen (bzw. einen Snapshot davon):<br />
<a href="http://de.wikipedia.org/wiki/Volume_Shadow_Copy_Service" rel="nofollow">http://de.wikipedia.org/wiki/Volume_Shadow_Copy_Service</a></p>
<p>...weniger aufwändig wäre sich einfach durch ein Kommandozeilen-Tool die ShadowCopy-Arbeit abnehmen zu lassen (z.B. hobocopy)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1734527</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1734527</guid><dc:creator><![CDATA[geeky]]></dc:creator><pubDate>Mon, 29 Jun 2009 12:46:45 GMT</pubDate></item><item><title><![CDATA[Reply to Datei im Binäry-Modi öffnen, Inhalt auslesen und dann kopieren. on Mon, 29 Jun 2009 21:09:22 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/18927">@DocShoe</a>:<br />
Dateien die man damit kopieren kann, kann man mit sogut wie jeder Funktion (inklusive CopyFile) kopieren, da du bei der Quelldatei nur FILE_SHARE_READ übergibst.</p>
<p>Das stellt zwar sicher dass keiner die Datei ändern kann während du kopierst, aber dafür kann man auch keine Dateien kopieren, die irgendein Programm zum Schreiben offen hat.</p>
<p>Wenn dann müsste man zumindest FILE_SHARE_READ | FILE_SHARE_WRITE (und evtl. noch FILE_SHARE_DELETE) angeben - nur dann kann man eben nichtmehr sicher sein eine &quot;unbeschädigte&quot; Kopie des Files zu bekommen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1734776</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1734776</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Mon, 29 Jun 2009 21:09:22 GMT</pubDate></item><item><title><![CDATA[Reply to Datei im Binäry-Modi öffnen, Inhalt auslesen und dann kopieren. on Mon, 29 Jun 2009 21:41:41 GMT]]></title><description><![CDATA[<p>kann sich vll auch jemand mein Problem mit dem binären lesen von Dateien anschauen?<br />
<a href="http://www.c-plusplus.net/forum/viewtopic-var-t-is-244359.html" rel="nofollow">http://www.c-plusplus.net/forum/viewtopic-var-t-is-244359.html</a></p>
<p>greetz</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1734787</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1734787</guid><dc:creator><![CDATA[KN4CK3R]]></dc:creator><pubDate>Mon, 29 Jun 2009 21:41:41 GMT</pubDate></item></channel></rss>