user33435: I'm currently using the SDFat library and am passing a global FatFile

I if have a function that requires an SdFile type and I know that a given instance of FatFile is a valid SdFile what is the best way to reopen FatFile F as SdFile J?
Right now I'm doing:
SdFile ActiveFile;  //Global Active File
...
void SDRun (FatFile &RunFat)
{
  SdFile RunRoot;
  RunRoot.open("/", O_READ);
  ActiveFile.close();
  ActiveFile.open(&RunRoot,RunFat.dirIndex(),O_READ);
  ....

However, this only works when RunFat is in the root directory.

user4143: If RunFat is an instance of SdFile you can just cast it:
SdFile& RunRoot = dynamic_cast<SdFile&>(RunFat);

RunRoot and RunFat are now the exact same file in the exact same state (no need to open it or anything) but seen as an SdFile not a FatFile.

33435: <p>I'm currently using the <a href="https://github.com/greiman/SdFat" rel="nofollow noreferrer">SDFat library</a> and am passing a global <code>FatFile</code></p>

<p><a href="https://i.stack.imgur.com/hgF8Y.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hgF8Y.png" alt="enter image description here"></a></p>

<p>I if have a function that requires an <code>SdFile</code> type and I know that a given instance of <code>FatFile</code> is a valid <code>SdFile</code> what is the best way to reopen <code>FatFile F</code> as <code>SdFile J</code>?</p>

<p>Right now I'm doing:</p>

<pre><code>SdFile ActiveFile;  //Global Active File
...
void SDRun (FatFile &amp;RunFat)
{
  SdFile RunRoot;
  RunRoot.open("/", O_READ);
  ActiveFile.close();
  ActiveFile.open(&amp;RunRoot,RunFat.dirIndex(),O_READ);
  ....
</code></pre>

<p>However, this only works when <code>RunFat</code> is in the root directory.</p>
 4143: <p>If <code>RunFat</code> is an instance of <code>SdFile</code> you can just cast it:</p>

<pre><code>SdFile&amp; RunRoot = dynamic_cast&lt;SdFile&amp;&gt;(RunFat);
</code></pre>

<p><code>RunRoot</code> and <code>RunFat</code> are now the exact same file in the exact same state (no need to open it or anything) but seen as an <code>SdFile</code> not a <code>FatFile</code>.</p>
