<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>[Win32] FindFirstFile - FindNextFile returning name of directory</title>
		<link>http://www.allegro.cc/forums/view/607839</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Sat, 16 Jul 2011 18:04:54 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;m trying to find all the files in a directory named &quot;en&quot; and no matter how many times I search through with FindNextFile, it always returns the same thing. &quot;en&quot; which is not a file or directory inside of \en. Anyone see a problem?</p><div class="source-code"><div class="toolbar"><span class="button numbers"><b>#</b></span><span class="button select">Select</span><span class="button expand">Expand</span></div><div class="inner"><span class="number">  1</span><span class="k1">if</span> <span class="k2">(</span><span class="k3">!</span>isADirectory<span class="k2">(</span>argv<span class="k2">[</span><span class="n">1</span><span class="k2">]</span><span class="k2">)</span><span class="k2">)</span>
<span class="number">  2</span>        <span class="k2">{</span>
<span class="number">  3</span>            <a href="http://www.delorie.com/djgpp/doc/libc/libc_624.html" target="_blank">printf</a><span class="k2">(</span><span class="s">"%s is not a directory."</span>,argv<span class="k2">[</span><span class="n">1</span><span class="k2">]</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  4</span>            <a href="http://www.delorie.com/djgpp/doc/libc/libc_298.html" target="_blank">exit</a><span class="k2">(</span><span class="n">1</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  5</span>        <span class="k2">}</span>
<span class="number">  6</span>        <span class="k1">else</span>
<span class="number">  7</span>        <span class="k2">{</span>
<span class="number">  8</span>            <a href="http://www.delorie.com/djgpp/doc/libc/libc_624.html" target="_blank">printf</a><span class="k2">(</span><span class="s">"%s is a directory.\n"</span>,argv<span class="k2">[</span><span class="n">1</span><span class="k2">]</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  9</span>        <span class="k2">}</span>
<span class="number"> 10</span>        
<span class="number"> 11</span>        WIN32_FIND_DATA wData<span class="k2">;</span>
<span class="number"> 12</span>        HANDLE wHandle<span class="k2">;</span>
<span class="number"> 13</span>
<span class="number"> 14</span>        wHandle <span class="k3">=</span> FindFirstFile<span class="k2">(</span>argv<span class="k2">[</span><span class="n">1</span><span class="k2">]</span>,<span class="k3">&amp;</span>wData<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 15</span>
<span class="number"> 16</span>        <a href="http://www.delorie.com/djgpp/doc/libc/libc_624.html" target="_blank">printf</a><span class="k2">(</span><span class="s">"First file in directory is: %s\n"</span>,wData.cFileName<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 17</span>
<span class="number"> 18</span>        <span class="k1">if</span> <span class="k2">(</span>wHandle <span class="k3">=</span><span class="k3">=</span> INVALID_HANDLE_VALUE<span class="k2">)</span>
<span class="number"> 19</span>        <span class="k2">{</span>
<span class="number"> 20</span>            <a href="http://www.delorie.com/djgpp/doc/libc/libc_624.html" target="_blank">printf</a><span class="k2">(</span><span class="s">"Error in finding a directory."</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 21</span>        <span class="k2">}</span>
<span class="number"> 22</span>
<span class="number"> 23</span>        FindNextFile<span class="k2">(</span>wHandle, <span class="k3">&amp;</span>wData<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 24</span>        <a href="http://www.delorie.com/djgpp/doc/libc/libc_624.html" target="_blank">printf</a><span class="k2">(</span><span class="s">"Second file in directory is: %s\n"</span>,wData.cFileName<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 25</span>        FindNextFile<span class="k2">(</span>wHandle, <span class="k3">&amp;</span>wData<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 26</span>        <a href="http://www.delorie.com/djgpp/doc/libc/libc_624.html" target="_blank">printf</a><span class="k2">(</span><span class="s">"Third file in directory is: %s\n"</span>,wData.cFileName<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 27</span>
<span class="number"> 28</span>        string fullpath_s <span class="k3">=</span> argv<span class="k2">[</span><span class="n">1</span><span class="k2">]</span><span class="k2">;</span>
<span class="number"> 29</span>        fullpath_s <span class="k3">+</span><span class="k3">=</span> <span class="s">"\\"</span><span class="k2">;</span>
<span class="number"> 30</span>        fullpath_s <span class="k3">+</span><span class="k3">=</span> wData.cFileName<span class="k2">;</span>
</div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (North~)</author>
		<pubDate>Wed, 13 Jul 2011 21:58:51 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>From looking at<br /><a href="http://msdn.microsoft.com/en-us/library/aa364418(v=vs.85).aspx">FindFirstFile</a><br /><a href="http://msdn.microsoft.com/en-us/library/aa364428(v=vs.85).aspx">FindNextFile</a><br /><a href="http://msdn.microsoft.com/en-us/library/aa365740(v=vs.85).aspx">WIN32_FIND_DATA</a><br />it seems you are using the functions properly.</p><p>So, that leaves the problem up to the path you are passing into your code as argv[1].</p><p>According to the docs, it seems you should be using a path like this :
</p><pre>
drive:\\folder\\en*
</pre><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Thu, 14 Jul 2011 09:37:37 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I have tried this before with single and double backspaces and the result is the same</p><p>First file: en<br />Second file: en<br />Third file: en</p><p>I am aware that the first two things in a folder are references to the folder itself &quot;.&quot; and the parent &quot;..&quot; but even if it was picking up these, the second &quot;file&quot; should be &quot;Desktop&quot; and the third should be the first file in the actual folder. However, this is not the case, and I am confused.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (North~)</author>
		<pubDate>Thu, 14 Jul 2011 22:23:05 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607839/924524#target">North~</a> said:</div><div class="quote"><p>
I&#39;m trying to find all the files in a directory named &quot;en&quot; and no matter how many times I search through with FindNextFile, it always returns the same thing. &quot;en&quot; which is not a file or directory inside of \en. Anyone see a problem?
</p></div></div><p>
I misread what you said earlier. I thought you were looking for all the files starting with &#39;en&#39;, not for all the files in a directory named &#39;en&#39;. You need to alter your search path to something like this :
</p><pre>
drive:\\folder\\en\\*
</pre><p>
(Only escape the backslashes if you aren&#39;t entering it in manually)</p><p>I assume before you were trying to search by using something like this :
</p><pre>
drive:\\folder\\en
</pre><p>
and that would only find the en folder, which is why it keeps showing up when you call FindNextFile.</p><p>Also, make sure you check the return value of FindNextFile. It will return false when there are no more matching files and then calling GetLastError will return ERROR_NO_MORE_FILES.</p><p>Since you&#39;re asking the user for a directory, you need to append a backslash if there isn&#39;t one, and an asterisk as a wildcard to match all files and folders within the directory specified.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Fri, 15 Jul 2011 09:32:57 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>That fixed it, thank you.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (North~)</author>
		<pubDate>Sat, 16 Jul 2011 18:04:54 +0000</pubDate>
	</item>
</rss>
