B4J Code Snippet Data Folder

Discussion in 'B4J Code Snippets' started by Erel, Aug 3, 2015.

  1. Erel

    Erel Administrator Staff Member Licensed User

    Edit: This method is now available internally with File.DirData.

    Windows apps are installed by default under Program Files. Starting from Windows Vista, Program Files folders are read-only. This means that writing to File.DirApp will fail.

    The following code returns a writable folder based on the platform:
    Code:
    Sub GetDataFolder (AppName As StringAs String
       
    Dim os As String = GetSystemProperty("os.name""").ToLowerCase
       
    If os.Contains("win"Then
        
    Dim wf As String = File.Combine(GetEnvironmentVariable("AppData"""), AppName)
        
    File.MakeDir(wf, "")
        
    Return wf
       
    Else
         
    Return File.DirApp
       
    End If
    End Sub
    It will return something like: C:\Users\H\AppData\Roaming\AppName on Windows and File.DirApp on other platforms.
     
    Last edited: Jan 3, 2016
  2. ThRuST

    ThRuST Well-Known Member Licensed User

    Does File.DirApp contains the project folder on non-Windows systems? Because it is not created in the above routine. So where is File.DirApp on Mac etc?
     
  3. Erel

    Erel Administrator Staff Member Licensed User

    This thread has nothing to do with File.DirApp.
    Please start a new thread for your question.
     
  4. Tirs

    Tirs Member Licensed User

    Well, File.DirData breaks the program when run under Windows XP, so this small piece of code is still useful. Thank you, Erel!
    Of course, I understand XP is not supported any more, so I don't consider this to be a bug.
    (Yes, I'm still building apps for Windows XP computers. Don't ask. Fortunately, they are not connected to the Internet).
     
    Last edited: Feb 9, 2018
    jahswani likes this.
  5. Erel

    Erel Administrator Staff Member Licensed User

    If I remember correctly File.DirData implementation is identical to the above code. What happens when you call File.DirData on Windows Xp?
     
  6. Tirs

    Tirs Member Licensed User

    Well, that's really odd...
    I removed the call to GetDataFolder and put back the File.DirData ...and now it works. I cannot reproduce the error any more. The program logic hasn't changed, so it's quite strange.
    I was getting a Java "File not found" exception. But it doesn't happen any more: now it works properly.
    Sorry I'm unable to give more info.
     
Loading...
  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