Android Question Creating a Directory

Gavin

Member
Licensed User
Longtime User
Hi everyone
Using the Sub below, I successfully write the file to the device and am able to read the file when the program opens and load the views with the correct data.
The problem I am having is understanding exactly how this is happening. I was hoping to create a directory named BlankSodoku off the root directory on the device, similar to windows c:/root/blanksodoku.
When I view the directory structures on my PC, I do not see /blanksodoku off the root directory.
My desire is to save the puzzle along with a small config file so the the last puzzle will open when the program opens. This I have also succeeded in doing but only if I place the KNOWN file name at the top of the program.
So what I need is to create the "root/blanksodoku" directory, be able to view all the files in this directory then choose the desired file and open the puzzle.
I have looked at the Files Documentation and tried everything I can think off, but I do not understand how to create the directory and the read the files in that directory.
Any assistance greatly appreciated.

B4X:
Sub WriteList(Fiall As String)
   
    Dim List1 As List
    List1.Initialize
    Dim Temp As String
   
    For I = 0 To 80
        List1.Add(l(I).Text)
        Temp = sf.Left(l(I).Tag, 1)   
        List1.Add(Temp)
        If Temp = "S" Then
            l(I).Enabled = False
            l(I).Color = Colors.Red
        End If
    Next
    If File.Exists(File.DirInternal,"/BlankSodoku, " & Fiall &".txt") Then
        File.WriteList(File.DirInternal,"/BlankSodoku, " & Fiall & ".txt", List1)
    Else
        If File.IsDirectory(File.DirInternal,"/BlankSodoku") = False Then File.MakeDir(File.DirInternal,"/BlankSodoku")
        File.WriteList(File.DirInternal,"/BlankSodoku, " & Fiall & ".txt", List1)
        File.WriteString(File.DirInternal,"/BlankSodoku, Config.txt", Fiall)    'The last puzzle we were compleating.
    End If
   
End Sub
 

Gavin

Member
Licensed User
Longtime User
Thank you LucaMs
Firstly, sorry for the incorrect spelling but that is irrelevant at this time.
I checked out your example, Public Sub ListFilesOnly(Dir As String) As List but am still having problems viewing the content of the folder, or is it a folder?
The example given in the File Lib is File.MakeDir(File.DirInternal, "music/90"). Now, using your example, if I wished to view the files in File.DirInternal, "music/90" would you do this.
B4X:
Dim FilesToView As String

FilesToView = File.DirInternal, music/90
'or would it be
'FilesToView = File.DirInternal, "music/90"
'or would it be
'FilesToView = File.DirInternal/ music/90

ListFilesOnly(FilesToView)
Public Sub ListFilesOnly(Dir As String) As List
    Dim lstDir, lstRes As List
    lstRes.Initialize
   
    If File.Exists(Dir, "") Then

        lstDir = File.ListFiles(Dir)
     
        Dim FileName As String
     
        For i = 0 To lstDir.Size - 1
            FileName = lstDir.Get(i)
            If Not(File.IsDirectory(Dir, FileName)) Then
                lstRes.Add(FileName)
            End If
        Next
     
    End If
 
    Return lstRes

End Sub

What is the correct format?
As I mentioned in my first post, I am definatly writing the file to the device and reading it back, that's no problem. Its just that I do not understand how to view the files. In the File Lib example, does the / have any signifagance in "music/90" or is it just part of the name since is enclosed in the quotations.

Thank You
 
Upvote 0
Top