Progress Algoritm Question

ozgureffe

Member
Licensed User
Longtime User
Hi, I have a problem in my program

My program checks if a specific directory exists
1) If NOT then It creates that folder & read all files in a list...
(It gives errors. It tries to read that folder before creating it)
How can I make my program to wait for creating that folders?

2) If YES then read all files in a list...
(Its Ok when that folder exists)


B4X:
Sub Activity_Create(FirstTime As Boolean)

   Activity.LoadLayout("main")
   
   If FirstTime Then
      CheckFolders
   End If
   
   LoadNotes
   
   
End Sub

Sub CheckFolders
   If File.Exists(File.DirRootExternal , "/fn/") = False Then
      File.MakeDir(File.DirRootExternal , "/fn/")
   End If
   
   If File.Exists(File.DirRootExternal , "/fn/notes") = False Then
      File.MakeDir(File.DirRootExternal , "/fn/notes")
   End If
   
   If File.Exists(File.DirRootExternal , "/fn/edit") = False Then
      File.MakeDir(File.DirRootExternal , "/fn/edit")
   End If
End Sub

Sub LoadNotes

Dim NoteFiles As List

   NoteFiles = File.ListFiles(File.DirRootExternal & "/fn/notes/")
   
   If NoteFiles.Size > 0 Then
   
   NoteFiles.Sort(True)

   ...

   End If
End Sub
 
Last edited:

kickaha

Well-Known Member
Licensed User
Longtime User
As you are only checking the existance of the files when Firsttime is true, I suspect that you ran the program then quit it and deleted the directories, then ran the program again at which point it failed as the directories did not exist.

This is because quitting an android progam does not automatically remove it from memory, so a subsequent run may find the program already ther, so Firsttime will be false.
 
Upvote 0
Top