Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

List SUBDir

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> KokkeKat FAT-free SD card lib
View previous topic :: View next topic  
Author Message
BASCOMB

Bascom Member



Joined: 02 Apr 2007
Posts: 3

germany.gif
PostPosted: Fri Jul 01, 2011 3:58 pm    Post subject: List SUBDir Reply with quote

Niclas,
Thanks for the great tool!
It works just fine.
how can I get a list of the Subdirectories of the root?
For example like “DIRLIST_Scroll or DEMO_Scroll”.

Would you have a small programm (demo) or any other idea ?

best regards, Ernst
Back to top
View user's profile
KokkeKat

Bascom Member



Joined: 08 May 2011
Posts: 59
Location: Stockholm

sweden.gif
PostPosted: Fri Jul 01, 2011 8:19 pm    Post subject: Reply with quote

Hi Ernst

Thanks for your appreciation! Smile

The dirlist routine is meant to be called from a loop, limited by Sddirliststartpoint=1, Sddirlistendpoint=1, or Sdstatus=32.
When you want to get a list of subdirectories (to any directory), do something like this:

' In the declaration section, define the size of the array that stores the current directory's clusters. You can set it to as low as 1, but you will get much faster directory scrolling if you don't have to follow the cluster chain for each previous cluster when going backwards. Below is just a "any" value.:
Const Sddirlistarraysize = 12

' The actual code:
Sdstartdirclusterd = 0 ' Set it to 0 as a dummy value for root directory - if FAT32, you can also set it to 2
Sdclusterd = Sdstartdirclusterd
Sddirlistarraycounter = 0
Sddirlistdirection = 0
Do
Sdstatus = 0
Gosub Sddirlist
If Sdstatus = 27 then
' Here you copy the content you need from array Sddirlistdirentry() (and the whereabouts) to your array that contains the subdirectory names.
' Or, just PRINT the name of each entry. (Especially when dealing with long file names, you probably won't want to store each 256-byte long LFN in an array...)
End If
Loop Until Sddirliststartpoint=1 Or Sddirlistendpoint=1 or Sdstatus=32

' From the Sddirlist code:
' Routine-specific Sdstatuses:
' 26 = A file entry has been found
' 27 = A directory entry has been found
' 28 = An available directory space has been found
' 32 = EOD End Of Directory marker found
' 33 = Subdirectory . or .. entry found
' 34 = A volume ID has been found
' 36 = Long file name found

' Since the first directory entry can't have both status and start of directory status, this bit indicates that we have returned to the starting point
' Sddirliststartpoint = 1 ' The directory backward listing has reached the starting point
' Sddirlistendpoint = 1 ' The directory forward listing has reached the end point
' Sddirlistoutside = 1 ' We have scrolled outside of Sddirlistarray() array

Kind regards

Niclas
Back to top
View user's profile
BASCOMB

Bascom Member



Joined: 02 Apr 2007
Posts: 3

germany.gif
PostPosted: Sat Jul 02, 2011 12:23 pm    Post subject: Reply with quote

hi Niclas,

thanks for the reply. The list of root I can therefore spend as you suggest
have you an example of how I'm spending the list of directories?

SD-Card:
SUBDIR1
SUBDIR2
| +--File21
| +--File22
SUBDIR 3
File1
File2

the below example works correctly and gives out the root:
SUBDIR1
SUBDIR2
SUBDIR 3
File1
File2

but how do I get a list of SUBDIR2: ??
File21
File22

please give me an example
best regards, Ernst

'+++++++++++++++++++++++++++++++++++++++++
Sdstatus = 0
Gosub Sdinit
If Sdstatus = 0 Then Gosub Sdinitfs
Sdstartdirclusterd = 0
Sdclusterd = Sdstartdirclusterd
Sddirlistarraycounter = 0
Sddirlistdirection = 0
Do
Sdstatus = 0
Gosub Sddirlist
if Sdstatus = 26 Or Sdstatus = 27 Then ' File oder Verzeichnis gefunden
Aset = ""
For Sdtempw2 = 1 To 12
Aset = Aset + Chr(sddirlistdirentry(Sdtempw2))
Next Sdtempw2
print #2 , "-->" ; Aset
End If
Loop Until Sdstatus = 32
'++++++++++++++++++++++++++++++++++++++++++++++
Back to top
View user's profile
KokkeKat

Bascom Member



Joined: 08 May 2011
Posts: 59
Location: Stockholm

sweden.gif
PostPosted: Sat Jul 02, 2011 5:17 pm    Post subject: Reply with quote

Hi Ernst

You need to find the cluster number, in which SUBDIR2 starts. Inside the loop that your describe, do something like this:

Dim Esddirfound As Bit

Sdstatus = 0
Gosub Sdinit

If Sdstatus = 0 Then
Gosub Sdinitfs
End If

If Sdstatus = 0 Then
Sdstartdirclusterd = 0
Sdclusterd = Sdstartdirclusterd
Sddirlistarraycounter = 0
Sddirlistdirection = 0
Esddirfound = 0

Do
Sdstatus = 0
Gosub Sddirlist
If Sdstatus = 27 then
' [If file/subdirectory name = "SUBDIR2" Then]
Sdclusterb(1) = Sddirlistdirentry(27)
Sdclusterb(2) = Sddirlistdirentry(28 )
Sdclusterb(3) = Sddirlistdirentry(21)
Sdclusterb(4) = Sddirlistdirentry(22)
Esddirfound = 1
' End If
End If
Loop Until Sddirliststartpoint=1 Or Sddirlistendpoint=1 or Sdstatus=32 Or Esddirfound = 1

If Esddirfound = 1 Then
Sdstartdirclusterd = Sdclusterd
' Here you do the loop you described
End If

End If

---

Please notice that you must end the loop at least with this:
Loop Until Sddirliststartpoint=1 Or Sddirlistendpoint=1 or Sdstatus=32
Only looking for Sdstatus = 32 will miss the case when the last directory entry is the very last entry in the cluster. (In which case it's the FAT that tells you that the current cluster is the last in the chain.)

Kind regards

Niclas
Back to top
View user's profile
njepsen

Bascom Member



Joined: 13 Aug 2007
Posts: 418

newzealand.gif
PostPosted: Sat Jul 02, 2011 11:19 pm    Post subject: Reply with quote

Niclas,
what doe the d on the end of the label sdstartclusterd mean?
neil

_________________
Neil
Back to top
View user's profile
BASCOMB

Bascom Member



Joined: 02 Apr 2007
Posts: 3

germany.gif
PostPosted: Sun Jul 03, 2011 9:00 am    Post subject: Reply with quote

Hi Niclas,

That was exactly the solution!.
Many thanks for your help.

best regards, Ernst
Back to top
View user's profile
KokkeKat

Bascom Member



Joined: 08 May 2011
Posts: 59
Location: Stockholm

sweden.gif
PostPosted: Sun Jul 03, 2011 1:29 pm    Post subject: Reply with quote

Hi Neil

The trailing letter (when it exists) means:
d = DWORD
l = LONG
w = WORD
b = BYTE

I use them especially when I overlay two variables. (See the declarations file for examples.)

Kind regards

---

I am happy to hear that I could help you Ernst. Smile

Kind regards

Niclas
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> KokkeKat FAT-free SD card lib All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum