B4R Question SD open next file

Discussion in 'B4R Questions' started by Mostez, Jul 16, 2018.

  1. Mostez

    Mostez Active Member

    I want to read files inside folder one after one and send data over USB. With rSD list files function i get list of files and read them one by one but if number of files are more than 50 or so MEGA starts over. I read this article about SD open next file and SD rewind directory and I want to know how to call it from inline C, or if it is easy to modify recent rSD library(sorry but I have no C experience).

  2. Peter Simpson

    Peter Simpson Expert Licensed User

    Can you post the code that you are using, the Mega should'nt be starting over.

    Have you read this posy by Erel, manipulating Inline C is extremely simple to do, even with little to no experience in C, just play about with the code until you get it working and most importantly learn from it.

    Inline C tutorial

    I use code something like this via an ESP8266, it can easily be modified to loop through and read every single file on an SD card...
    Dim SDCard As SD
    4'Pins 4 and 8 work (maybe also 10 on other devices)
        For Each F As File In SDCard.ListFiles("/")
    Log("Name: ", F.Name, ", Size: ", F.Size)
    Dim Buffer(SDCard.CurrentFile.Size) As Byte
    0, SDCard.CurrentFile.Size)
  3. Mostez

    Mostez Active Member

    Thanks for reply, yes I read Erel's post, but I don't know how to integrate inline-C SD object with used SD object in B4R code? here is the code I use.

    private Sub UploadAllUserAccounts(SendFileInfo As Boolean,StreamSource As AsyncStreamsAs Boolean
    Dim Size As ULong = 0
    0,1,"Please Wait...",True)
    If SendFileInfo Then
    For Each Fl As File In SD.ListFiles("dat"' get total file size in folder
                Size = Size + 66 + 2 'only first four fields
    'send file info only for once, upload user files as stream of ONE united file
            Dim Tmp(18As Byte
    Dim RAF As RandomAccessFile
    NumberFormat(Size,8,0).GetBytes,0,8,RAF.CurrentPosition) 'file size
    End If
    'Dim cb(101) As Byte
        Dim cb(66As Byte
    For Each f As File In SD.ListFiles("dat")
    If SD.OpenRead(GetUserAccountFileName(f.Name)) = False  Then
    Return False
    End If
    'SD.Stream.ReadBytes(cb,0,101) 'read 101 bytes
            SetSD (OFF)
            SetSD (ON)
        SetSD (OFF)
    Array As Byte (0x04),1,True,StreamSource)'end of transmission
        'SetSD (True)
        Return True
    End Sub
    private Sub SendStreamMessage(Message() As Byte,BytestoSend As Byte,SendCRLF As Boolean,StreamSource As AsyncStreams)
    If SendCRLF Then
    Dim ForSend(BytestoSend + 2As Byte
            ForSend(BytestoSend) = 
            ForSend(BytestoSend + 
    1) = 0x0A
    Dim ForSend(BytestoSend) As Byte
    End If
    End Sub
  4. Erel

    Erel Administrator Staff Member Licensed User

    Inline C will not help here.

    Does this code work:
    For Each F As File In SDCard.ListFiles("/")
    Log("Name: ", F.Name, ", Size: ", F.Size)
  5. Mostez

    Mostez Active Member

    Yes Erel, it worked OK with 75 files in folder
    EDIT: i increased number of files to 225, listed OK
    Last edited: Jul 16, 2018
  6. Erel

    Erel Administrator Staff Member Licensed User

    To answer your question from the first post, using inline C will not help at all. There is no problem with iterating over hundreds of files. The problem is in the code that handles each file. For further discussion please start a new thread and post the relevant code.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice