<?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[Problem mit FindFirstFile]]></title><description><![CDATA[<p>Hallo zusammen!</p>
<p>Bei uns im Studium (TU Chemnitz) sollen wir für die Vorlesung Betriebssysteme kleine Programme schreiben um mal zu sehn, was Betriebssysteme so machen. Erste Aufgabe war, die Summe aller Dateigrößen eines Verzeichnisses zu berechnen.</p>
<p>Ich hab nun Probleme bei der Lösung unter Windows. Und zwar ist das Ergebnis von FindFirstFile immer INVALID_HANDLE_VALUE.</p>
<p>Hier mal mein Code:</p>
<pre><code class="language-cpp">#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;windows.h&gt;
#include &lt;sys/types.h&gt;
#include &lt;sys/stat.h&gt;

unsigned int sumOfFileSizes(char *path)
{
 	char 			dirname[MAX_PATH];
 	unsigned int 	sum 						= 0;
 	WIN32_FIND_DATA fileInfos;
   	HANDLE 			hFind 						= INVALID_HANDLE_VALUE;
   	DWORD			dwError;

	strcpy (dirname, path);
	//strncpy (dirname, path, strlen(path)+1);
   	strcat (dirname, &quot;\\*&quot;);
	//strncat (dirname, &quot;\\*&quot;, 3);

   	hFind = FindFirstFile(dirname, &amp;fileInfos);

    if (hFind == INVALID_HANDLE_VALUE) 
    {
		printf (&quot;Invalid file handle. Error is %u\n&quot;, GetLastError());
    	return 0;
   	} 
   	else 
   	{
   		if ((fileInfos.cFileName != &quot;.&quot;)||
   			(fileInfos.cFileName != &quot;..&quot;))
   		{
   			if (fileInfos.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY)
   				sum += sumOfFileSizes(fileInfos.cFileName);
   			else sum += (fileInfos.nFileSizeHigh * (MAXDWORD+1)) + fileInfos.nFileSizeLow;
   		};

      	while (FindNextFile(hFind, &amp;fileInfos) != 0) 
      	{
         	if ((fileInfos.cFileName != &quot;.&quot;)||
	   			(fileInfos.cFileName != &quot;..&quot;))
	   		{
	   			if (fileInfos.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY)
	   				sum += sumOfFileSizes(fileInfos.cFileName);
	   			else sum += (fileInfos.nFileSizeHigh * (MAXDWORD+1)) + fileInfos.nFileSizeLow;
	   		};
      	}
   	}

   	printf(&quot;%s&quot;, path);
   	dwError = GetLastError();
   	FindClose(hFind);
  	if (dwError != ERROR_NO_MORE_FILES) 
  	{
     	printf (&quot;FindNextFile error. Error is %u\n&quot;, dwError);
     	return (0);
  	}

	return sum;
};

// Mainfunction
int main (int argc, char *argv[])
{
 	/*if (argc != 2) //check if exactly 1 parameter is given (path for sumation)
 	{
 		printf(&quot;Call program with exactly one parameter. (FileSizeCounter &lt;startpath&gt;)\n&quot;);
 		printf(&quot; (FileSizeCounter will count all sub directorys, too!)&quot;);
 	} else printf(&quot;Sum of the size of all files in all sub directorys: %u\n&quot;,sumOfFileSizes(argv[1]));*/

 	printf(&quot;Sum of the size of all files in all sub directorys: %u\n&quot;
            , sumOfFileSizes(&quot;C:\\Programmieren\\EclipsePorjects\\Betriebssysteme\0&quot;));
 	return 0;
}
</code></pre>
<p>Das es in der Main() so wild aussieht, liegt daran, dass ich Probleme hatte in meiner GUI Parameter zu übergeben. Deshalb erstmal diese Manuelle Pfadangabe. Ich hab selbige auch schon ohne dem &quot;\0&quot; probiert. Ändert aber nix.</p>
<p>Könnt ihr mir sagen wieso nun FindFirstFile mir kein gültiges Handle gibt?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/123387/problem-mit-findfirstfile</link><generator>RSS for Node</generator><lastBuildDate>Tue, 07 Jul 2026 19:10:16 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/123387.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 16 Oct 2005 11:23:40 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Problem mit FindFirstFile on Sun, 16 Oct 2005 11:23:40 GMT]]></title><description><![CDATA[<p>Hallo zusammen!</p>
<p>Bei uns im Studium (TU Chemnitz) sollen wir für die Vorlesung Betriebssysteme kleine Programme schreiben um mal zu sehn, was Betriebssysteme so machen. Erste Aufgabe war, die Summe aller Dateigrößen eines Verzeichnisses zu berechnen.</p>
<p>Ich hab nun Probleme bei der Lösung unter Windows. Und zwar ist das Ergebnis von FindFirstFile immer INVALID_HANDLE_VALUE.</p>
<p>Hier mal mein Code:</p>
<pre><code class="language-cpp">#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;windows.h&gt;
#include &lt;sys/types.h&gt;
#include &lt;sys/stat.h&gt;

unsigned int sumOfFileSizes(char *path)
{
 	char 			dirname[MAX_PATH];
 	unsigned int 	sum 						= 0;
 	WIN32_FIND_DATA fileInfos;
   	HANDLE 			hFind 						= INVALID_HANDLE_VALUE;
   	DWORD			dwError;

	strcpy (dirname, path);
	//strncpy (dirname, path, strlen(path)+1);
   	strcat (dirname, &quot;\\*&quot;);
	//strncat (dirname, &quot;\\*&quot;, 3);

   	hFind = FindFirstFile(dirname, &amp;fileInfos);

    if (hFind == INVALID_HANDLE_VALUE) 
    {
		printf (&quot;Invalid file handle. Error is %u\n&quot;, GetLastError());
    	return 0;
   	} 
   	else 
   	{
   		if ((fileInfos.cFileName != &quot;.&quot;)||
   			(fileInfos.cFileName != &quot;..&quot;))
   		{
   			if (fileInfos.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY)
   				sum += sumOfFileSizes(fileInfos.cFileName);
   			else sum += (fileInfos.nFileSizeHigh * (MAXDWORD+1)) + fileInfos.nFileSizeLow;
   		};

      	while (FindNextFile(hFind, &amp;fileInfos) != 0) 
      	{
         	if ((fileInfos.cFileName != &quot;.&quot;)||
	   			(fileInfos.cFileName != &quot;..&quot;))
	   		{
	   			if (fileInfos.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY)
	   				sum += sumOfFileSizes(fileInfos.cFileName);
	   			else sum += (fileInfos.nFileSizeHigh * (MAXDWORD+1)) + fileInfos.nFileSizeLow;
	   		};
      	}
   	}

   	printf(&quot;%s&quot;, path);
   	dwError = GetLastError();
   	FindClose(hFind);
  	if (dwError != ERROR_NO_MORE_FILES) 
  	{
     	printf (&quot;FindNextFile error. Error is %u\n&quot;, dwError);
     	return (0);
  	}

	return sum;
};

// Mainfunction
int main (int argc, char *argv[])
{
 	/*if (argc != 2) //check if exactly 1 parameter is given (path for sumation)
 	{
 		printf(&quot;Call program with exactly one parameter. (FileSizeCounter &lt;startpath&gt;)\n&quot;);
 		printf(&quot; (FileSizeCounter will count all sub directorys, too!)&quot;);
 	} else printf(&quot;Sum of the size of all files in all sub directorys: %u\n&quot;,sumOfFileSizes(argv[1]));*/

 	printf(&quot;Sum of the size of all files in all sub directorys: %u\n&quot;
            , sumOfFileSizes(&quot;C:\\Programmieren\\EclipsePorjects\\Betriebssysteme\0&quot;));
 	return 0;
}
</code></pre>
<p>Das es in der Main() so wild aussieht, liegt daran, dass ich Probleme hatte in meiner GUI Parameter zu übergeben. Deshalb erstmal diese Manuelle Pfadangabe. Ich hab selbige auch schon ohne dem &quot;\0&quot; probiert. Ändert aber nix.</p>
<p>Könnt ihr mir sagen wieso nun FindFirstFile mir kein gültiges Handle gibt?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/893367</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/893367</guid><dc:creator><![CDATA[KFlash]]></dc:creator><pubDate>Sun, 16 Oct 2005 11:23:40 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit FindFirstFile on Sun, 16 Oct 2005 11:55:47 GMT]]></title><description><![CDATA[<p>Für den rekursiven Aufruf musst du dir erst den Pfad wieder aus path und fileInfos.cFileName zusammensetzen, da in letzerem nur der Verzeichnisname steht und nicht der vollständige Pfad <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/893387</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/893387</guid><dc:creator><![CDATA[flenders]]></dc:creator><pubDate>Sun, 16 Oct 2005 11:55:47 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit FindFirstFile on Sun, 16 Oct 2005 12:09:27 GMT]]></title><description><![CDATA[<p>Stringvergleiche macht man mit (l)strcmp.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/893396</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/893396</guid><dc:creator><![CDATA[l]]></dc:creator><pubDate>Sun, 16 Oct 2005 12:09:27 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit FindFirstFile on Sun, 16 Oct 2005 12:37:57 GMT]]></title><description><![CDATA[<p>Danke euch beiden. Das wären bestimmt zwei Probleme gewesen, auf die ich noch gestoßen wäre. Das Problem ist allerdings, dass bereits bei FindFirstFile ein ungültiges Handle naja...eher kein Handle zurückgeliefert wird.<br />
Soweit kommt das Programm also gar nicht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/893418</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/893418</guid><dc:creator><![CDATA[KFlash]]></dc:creator><pubDate>Sun, 16 Oct 2005 12:37:57 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit FindFirstFile on Sun, 16 Oct 2005 15:22:51 GMT]]></title><description><![CDATA[<p>hoi</p>
<p>vielleicht liegt der fehler in</p>
<pre><code class="language-cpp">printf(&quot;Sum of the size of all files in all sub directorys: %u\n&quot;
       ,sumOfFileSizes(&quot;C:\\Programmieren\\EclipsePorjects\\Betriebssysteme\0&quot;));
</code></pre>
<p>Sollte der pfad vielleicht</p>
<pre><code>&quot;C:\\Programmieren\\EclipseP[b]rojects[/b]\\Betriebssysteme\0&quot;
</code></pre>
<p>heissen ?</p>
<p>Meep Meep</p>
]]></description><link>https://www.c-plusplus.net/forum/post/893518</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/893518</guid><dc:creator><![CDATA[Meep Meep]]></dc:creator><pubDate>Sun, 16 Oct 2005 15:22:51 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit FindFirstFile on Sun, 16 Oct 2005 15:34:14 GMT]]></title><description><![CDATA[<p>KFlash schrieb:</p>
<blockquote>
<p>Das Problem ist allerdings, dass bereits bei FindFirstFile ein ungültiges Handle naja...eher kein Handle zurückgeliefert wird.<br />
Soweit kommt das Programm also gar nicht.</p>
</blockquote>
<p>Bei mir trat bei deinem Code dieser Fehler erst beim 2. (rekursiven Aufruf auf) - also der erste Aufruf von FindFirstFile lieferte ein gültiges Handle...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/893529</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/893529</guid><dc:creator><![CDATA[flenders]]></dc:creator><pubDate>Sun, 16 Oct 2005 15:34:14 GMT</pubDate></item></channel></rss>