user33435: I'm using the SdFat Library's sd.ls(LS_R) function to give me a serial output stream of all files on an SD card. My issue is that I would like to have it use a different character than '\n' at the end of each line as I'm using it as a termchar for my overall comms protocol. How can I get it to print a : or (another symbol that doesn't appear in file names) instead of a \ln

user38709: I am currently trying to have fun Modding my own sd.ls().
Worst way, modifying the library:
Go into FatFilePrint.cpp 
(Suggestion: Create yourself a new 'flag' like LS_COMMA)
Find the line
void FatFile::ls(print_t* pr, uint8_t flags, uint8_t indent) { ...

add your flag
if (flag & !LS_COMMA) {
   pr-->write(':');
} else {
    //original library set of 
    // pr->write(stuff);
}

--> SuperClass version # (prefered )
this will override the original ls() method by creating a new Class inheriting from the original one.
rather then invoking it from "volume", 
    sd.ls( your params);
invoke it from a directory file instead.
superFatFile rootDir;
rootDir.open("/");
rootDir.ls( __your_params__);

Place this superClass declaration in your .h
don't hesitate to remove any of the "flags" related code if YOUR requirement never calls for them.
class superFatFile : public FatFile {
    public:
    void ls(print_t* pr, uint8_t flags /* = 0 */, uint8_t indent /* = 0 */){
        superFile file;
        rewind();
        while (file.openNext(this, O_READ)) {
            if (!file.isHidden() || (flags & LS_A)) {
                // adds 'spaces' indent for dir level
                for (uint8_t i = 0; i < indent; i++) {
                    pr->write(' ');
                }

                if (flags & LS_DATE) {
                    file.printModifyDateTime(pr);
                    pr->write(' ');
                }

                if (flags & LS_SIZE) {
                    file.printFileSize(pr);
                    pr->write(' ');
                }

                // prints filename
                if (!file.isDir()) {    
                    file.printName(pr);
                    pr->write('\r');
                    pr->write('\n');    // HERE IS YOUR SEPARATOR CARACTERS !!!
                }

                // execute recursivly if LS_R flag was set
                if ((flags & LS_R) && file.isDir()) file.ls(pr, flags, indent + 2);

            }

        }
        file.close();
    } // end of new LS method
}; // end of superClass


33435: <p>I'm using the <a href="https://github.com/greiman/SdFat" rel="nofollow noreferrer">SdFat Library's</a> <code>sd.ls(LS_R)</code> function to give me a serial output stream of all files on an SD card. My issue is that I would like to have it use a different character than '\n' at the end of each line as I'm using it as a termchar for my overall comms protocol. How can I get it to print a <code>:</code> or (another symbol that doesn't appear in file names) instead of a <code>\ln</code></p>
 38709: <p>I am currently trying to have fun Modding my own sd.ls().</p>

<p>Worst way, modifying the library:</p>

<p>Go into FatFilePrint.cpp </p>

<p>(Suggestion: Create yourself a new 'flag' like LS_COMMA)</p>

<p>Find the line</p>

<pre><code>void FatFile::ls(print_t* pr, uint8_t flags, uint8_t indent) { ...
</code></pre>

<p>add your flag</p>

<pre><code>if (flag &amp; !LS_COMMA) {
   pr--&gt;write(':');
} else {
    //original library set of 
    // pr-&gt;write(stuff);
}
</code></pre>

<h1>--> SuperClass version # (prefered )</h1>

<p>this will override the original ls() method by creating a new Class inheriting from the original one.</p>

<p>rather then invoking it from "volume", 
    sd.ls( <strong>your params</strong>);</p>

<p>invoke it from a directory file instead.</p>

<pre><code>superFatFile rootDir;
rootDir.open("/");
rootDir.ls( __your_params__);
</code></pre>

<p>Place this superClass declaration in your .h
don't hesitate to remove any of the "flags" related code if YOUR requirement never calls for them.</p>

<pre><code>class superFatFile : public FatFile {
    public:
    void ls(print_t* pr, uint8_t flags /* = 0 */, uint8_t indent /* = 0 */){
        superFile file;
        rewind();
        while (file.openNext(this, O_READ)) {
            if (!file.isHidden() || (flags &amp; LS_A)) {
                // adds 'spaces' indent for dir level
                for (uint8_t i = 0; i &lt; indent; i++) {
                    pr-&gt;write(' ');
                }

                if (flags &amp; LS_DATE) {
                    file.printModifyDateTime(pr);
                    pr-&gt;write(' ');
                }

                if (flags &amp; LS_SIZE) {
                    file.printFileSize(pr);
                    pr-&gt;write(' ');
                }

                // prints filename
                if (!file.isDir()) {    
                    file.printName(pr);
                    pr-&gt;write('\r');
                    pr-&gt;write('\n');    // HERE IS YOUR SEPARATOR CARACTERS !!!
                }

                // execute recursivly if LS_R flag was set
                if ((flags &amp; LS_R) &amp;&amp; file.isDir()) file.ls(pr, flags, indent + 2);

            }

        }
        file.close();
    } // end of new LS method
}; // end of superClass
</code></pre>
