B4J Question Delete Directory

An Schi

Well-Known Member
Licensed User
How do i delete a directory?

The directory is created when doing this:

B4X:
    map.Put(TextField1.Text, TextField2.Text)
    File.WriteMap(File.DirData("Save Test"), "savetest.txt", map)

I have tried this (with and without the test for file.exists). Both didn't delete the directory. And yes - the directory is empty, because i delete the .txt file first. This works. It is located in C:\Users\[user name]\AppData\Roaming\[AppName], where [AppName] is "Save Test".

B4X:
    If File.Exists(File.DirData("Save Test"), File.DirData("Save Test")) = True Then
        File.Delete(File.DirData("Save Test"), File.DirData("Save Test"))
    End If
 

An Schi

Well-Known Member
Licensed User
This doesn't delete the folder as well. It is still there.
I tried: Log(File.Delete(File.DirData("Save Test"), "")) and it returns true, allthough the folder is existant.
I also tried to replace the space with an underscore, no deletion as well.

I am on Win10 64bit, if this might be important.

Edit:
I'm trying this in release mode with an UI app. I don't use the installer, just compile & run from IDE.
 
Upvote 0

An Schi

Well-Known Member
Licensed User
Thanks Erel for your help!
With your code it is working now.

It is indeed very confusing. If i use your code and after that if i use IfFile.Exists(File.DirData("Save Test") it will return false for not being existant. However it will be immediately recreated because the use of DirData in the If....

I'm not sure why you want to delete it

This has no explicit use. I'm just playing around with B4J trying and learning some things. I thought when my programm creates a file or a folder, it should also delete this file or folder. I know this is not directly related, but i hate it when i uninstall software and there are files and folders left over...

BTW: The documentation doesn't mention this delete & recreate behaviour at all.
Additional i asked the question in the beginning, cause the documentation missleaded me. It says:

https://b4x.com/b4j/help/files.html#file

The bold part made me think that i have to use the directory as filename, like i did in the very first post.
Maybe it was just me, maybe this is missleading and could be improoved
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…