Coder Social home page Coder Social logo

open by index and LFN about sdfat-beta HOT 5 CLOSED

greiman avatar greiman commented on August 29, 2024
open by index and LFN

from sdfat-beta.

Comments (5)

greiman avatar greiman commented on August 29, 2024

There is more than one directory entry for each file with a long file name. The only reliable way to get the correct index is to open the file by path and save the index.

The short file name entry is used to open the file. It is the last entry in the group. You must have the index of the first entry in the group to get the file name.

There can be isolated empty directory entries that can't be used for any lFN file.

So don't expect open by index to work if you an index other than to one returned by open by path.

from sdfat-beta.

greiman avatar greiman commented on August 29, 2024

Open by index on SdFat-beta opens the SFN directory entry and does not determine the LFN offset.

I will modify open by index to set the LFN offset.

from sdfat-beta.

mr-stivo avatar mr-stivo commented on August 29, 2024

I was just finishing this up when I saw you posted another reply. I still wanted to show you how I was using open by index.

Here is a better example of how I'm using open by index. The reason I use it this way is I'm displaying a scrollable directory listing and sometimes the directories have 100s of files. Since the memory is limited, keeping the index for the "top" of the list is much easier and I don't have the performance hit of parsing the entire directory multiple times.

You can change the library and the USE_SD_BETA define. teensy 3.6.

Code:

#include "SdFat.h"

#define USE_SD_BETA 0

#if USE_SD_BETA
#define SD_CONFIG SdSpiConfig(SDCARD_SS_PIN, DEDICATED_SPI)
SdFat sd;
#else
SdFatSdio sd;
#endif

File dir;
File file;

char n[512];

void setup() {
    Serial.begin(9600);
  
    while (!Serial) SysCall::yield();
  
    Serial.println("Type any character to start");
    while (!Serial.available()) SysCall::yield();

#if USE_SD_BETA
    if (!sd.begin(SD_CONFIG)) sd.initErrorHalt(&Serial);
#else
    if (!sd.begin()) sd.initErrorHalt(&Serial);
#endif
    
    if (!dir.open("/testdir")) Serial.println("dir.open failed");

    Serial.println("\n-- openNext --");
    while (file.openNext(&dir, O_RDONLY) ) {
        if(file.isHidden()==false) {
            file.getName(n, 512);
            Serial.printf("[%s]\n", n);
        }
        file.close();
    }

    Serial.println("\n-- open by index --");
    for(int i=0; i<25; i++) {
        if(file.open(&dir, i, O_RDONLY) && file.isHidden()==false) {
            file.getName(n, 512);
            Serial.printf("[%s]\n", n);
        }
        file.close();
    }
}

void loop() {
}

Using SdFat:

-- openNext --
[With.Two dots.txt]
[A long name can be 255 characters.txt]
[lower.txt]
[MIXCASE.txt]
[mixed.TXT]
[Not_8_3.txt]
[OK%83.TXT]
[STD_8_3.TXT]
[With Blank.txt]
[sub folder]

-- open by index --
[With.Two dots.txt]
[A long name can be 255 characters.txt]
[lower.txt]
[MIXCASE.txt]
[mixed.TXT]
[Not_8_3.txt]
[OK%83.TXT]
[STD_8_3.TXT]
[With Blank.txt]
[sub folder]

Using SdFat-beta:

-- openNext --
[With.Two dots.txt]
[A long name can be 255 characters.txt]
[lower.txt]
[MIXCASE.txt]
[mixed.TXT]
[Not_8_3.txt]
[OK%83.TXT]
[STD_8_3.TXT]
[With Blank.txt]
[sub folder]

-- open by index --
[WITHTW~1.TXT]
[ALONGN~1.TXT]
[lower.txt]
[MIXCASE.txt]
[mixed.TXT]
[NOT_8_3.TXT]
[OK%83.TXT]
[STD_8_3.TXT]
[WITHBL~1.TXT]
[SUBFOL~1]

from sdfat-beta.

greiman avatar greiman commented on August 29, 2024

Try the latest version. getName should work for LFN files opened by index.

from sdfat-beta.

mr-stivo avatar mr-stivo commented on August 29, 2024

The latest version is working well:

-- open by index --
[With.Two dots.txt]
[A long name can be 255 characters.txt]
[lower.txt]
[MIXCASE.txt]
[mixed.TXT]
[Not_8_3.txt]
[OK%83.TXT]
[STD_8_3.TXT]
[With Blank.txt]
[sub folder]

Thanks so much for the quick fix!

from sdfat-beta.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.