<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>File system routines - al_get_path_tail() returning wrong path component</title>
		<link>http://www.allegro.cc/forums/view/618038</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Mon, 03 Feb 2020 16:44:37 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>EDIT: Solved!</p><p>Years back I made a function that check for which mods are available in subfolders under a subfolder called &quot;Mods&quot; in my game&#39;s project directory. When finding a mod the name is stored and used for loading different assets.<br />However now some of the file system routines that previously worked fine are no longer doing the same thing. I don&#39;t know if it is a combination of Windows 10 + Allegro 5.0 or something else.<br />Anyone else know if new versions of Allegro have had changes made to adapt to file system changes in newer versions of Windows?</p><p>Here&#39;s a simplified code snippet of what I am doing and the results I get:
</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>ALLEGRO_PATH <span class="k3">*</span>ap<span class="k2">;</span>
<span class="number">  2</span><span class="k1">char</span> <span class="k3">*</span>projectPath<span class="k2">;</span>
<span class="number">  3</span><span class="k1">char</span> <span class="k3">*</span>projectName<span class="k2">;</span>
<span class="number">  4</span>...
<span class="number">  5</span><span class="k1">while</span><span class="k2">(</span><span class="k1">true</span><span class="k2">)</span>
<span class="number">  6</span><span class="k2">{</span>
<span class="number">  7</span>   ap <span class="k3">=</span> createAnAllegroPathToEachSubfolderUnderTheModsFolder<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  8</span>   ...
<span class="number">  9</span>   <a href="http://www.delorie.com/djgpp/doc/libc/libc_737.html" target="_blank">sprintf</a><span class="k2">(</span>modPath, <span class="s">"%s\\file.txt"</span>, <a href="http://www.allegro.cc/manual/al_path_cstr"><span class="a">al_path_cstr</span></a><span class="k2">(</span>ap, ALLEGRO_NATIVE_PATH_SEP<span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 10</span>   ...
</div></div><p>
projectPath will contain the correct full path &quot;C:\\Projects\\MyProject\\Mods\\Zelda\\file.txt&quot;.</p><p>However when using al_get_path_tail() I do not get the last component in the path but the second to last:
</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"> 10</span>   ...
<span class="number"> 11</span>   <a href="http://www.delorie.com/djgpp/doc/libc/libc_737.html" target="_blank">sprintf</a><span class="k2">(</span>projectName, <a href="http://www.allegro.cc/manual/al_get_path_tail"><span class="a">al_get_path_tail</span></a><span class="k2">(</span>ap<span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 12</span>   ...
<span class="number"> 13</span><span class="k2">}</span>
</div></div><p>
projectName will contain &quot;Mods&quot; instead of &quot;Zelda&quot;.</p><p>Same result will happen when using al_get_path_component() with -1 (first from right) as component id:
</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"> 10</span>   ...
<span class="number"> 11</span>   <a href="http://www.delorie.com/djgpp/doc/libc/libc_737.html" target="_blank">sprintf</a><span class="k2">(</span>projectName, <a href="http://www.allegro.cc/manual/al_get_path_component"><span class="a">al_get_path_component</span></a><span class="k2">(</span>ap, <span class="k3">-</span><span class="n">1</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 12</span>   ...
<span class="number"> 13</span><span class="k2">}</span>
</div></div><p>
projectName will again contain &quot;Mods&quot; instead of &quot;Zelda&quot;.</p><p>It&#39;s like the last component of the path is ignored but back in 2003 when I used the code it worked. The only thing I can think of that has changed is my Windows version.</p><p>Trying to find a newer version of Allegro (5.2.5) to try that but no luck finding binaries of this (yet).</p><p>---</p><p>EDIT: I just noticed that my ALLEGRO_PATH *get_next_subdirectory_in_directory() function used:<br /><span class="source-code"><span class="k1">return</span> <a href="http://www.allegro.cc/manual/al_create_path"><span class="a">al_create_path</span></a><span class="k2">(</span><span class="k2">(</span><span class="k1">char</span><span class="k3">*</span><span class="k2">)</span><a href="http://www.allegro.cc/manual/al_get_fs_entry_name"><span class="a">al_get_fs_entry_name</span></a><span class="k2">(</span>file<span class="k2">)</span><span class="k2">)</span><span class="k2">;</span></span><br />Instead of:<br /><span class="source-code"><span class="k1">return</span> <a href="http://www.allegro.cc/manual/al_create_path_for_directory"><span class="a">al_create_path_for_directory</span></a><span class="k2">(</span><span class="k2">(</span><span class="k1">char</span><span class="k3">*</span><span class="k2">)</span><a href="http://www.allegro.cc/manual/al_get_fs_entry_name"><span class="a">al_get_fs_entry_name</span></a><span class="k2">(</span>file<span class="k2">)</span><span class="k2">)</span><span class="k2">;</span></span></p><p>So a bug due to me. However I don&#39;t think I&#39;ve touched this code since 2013...aaand I think it worked back then. But who remembers. Oh well, problem solved!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (TeaRDoWN)</author>
		<pubDate>Mon, 03 Feb 2020 16:44:37 +0000</pubDate>
	</item>
</rss>
