B4J Question Check discs and possibly write to them

red30

Active Member
Licensed User
One of my disks used to be a system C: \. After I put ssd, and this drive became D: \
Now it is impossible to record files with it through b4j.
Is it possible to first check for the availability of discs and the ability to write files to them?
So that first I determine which disks I have, and then the possibility to write to each of them, in order to make further a decision on where to write the file.
Is it possible to still write files to C: \?
 
Last edited:

red30

Active Member
Licensed User
I probably did not write correctly. I meant that I had a hard drive (it was split into 2 areas C: \ and D: \), after that I bought an ssd drive, and it became drive C: \, and the hard one shifted to D: \ and E: \. And on the current disk D: \ I can not write anything.But the question was different. How can I check which drives I have, and on which ones can I write files?Can I somehow write files to the root of the C: \ drive?
 

red30

Active Member
Licensed User
How can I check whether it is possible to write a file in this path?
I found an example of checking the ability to create a folder, but where you can create a folder, you cannot always write a file ...
 

Kiffi

Well-Known Member
Licensed User
B4X:
Sub CheckPath(Path As String) As Boolean
   
    Try
        Dim Filename As String = "testfile" & DateTime.Now & ".txt"
        File.WriteString(Path, Filename, "test")
        File.Delete(Path, Filename)
        Return True
    Catch
        Return False
        ' Log(LastException)
    End Try
   
End Sub

Log(CheckPath("C:\"))
Log(CheckPath("E:\"))
As written, though: It's not a good idea to write directly to the root of a drive.
My recommendation: Use File.DirData to store your data.
 
Top