Makedir on SD card failed

Discuss any general programming issues here
Post Reply
amyren
Posts: 87
Joined: Thu May 02, 2019 11:53 am

Makedir on SD card failed

Post by amyren » Tue Sep 24, 2019 10:58 am

I try to make my app to create a directory on my SD card, but it fails with the error message:
"Error creating directory /storage/emulated/0/mydir !"
And it points to the line 311 in my script, which is the makedir line

Code: Select all

		t = GetVersion()
		If t.platform = "Android"
			If PermissionRequest(#PERMREQ_WRITEEXTERNAL)
				t = GetSystemInfo()
				mydir$ = t.SDCard.."/mydir"
				MakeDirectory(mydir$)

User avatar
airsoftsoftwair
Posts: 3219
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Makedir on SD card failed

Post by airsoftsoftwair » Fri Sep 27, 2019 11:34 pm

Which Android version is that?

amyren
Posts: 87
Joined: Thu May 02, 2019 11:53 am

Re: Makedir on SD card failed

Post by amyren » Mon Sep 30, 2019 12:24 pm

This was on android 9, but I also get the same error on my tablet, which runs android 8.1.0, and on my old phone with android 4.2.1.
I also did a test by using t.t.ExternalStorage instead of t.SDcard, but this also result in a similar error.

Using ES-fileExplorer I do notice that if I stay at folder which apear to be /storage/emulated/0, and then go up one directory then I will be at /storage/emulated which is empty
Googling this issue reveal other usersdebating this issue https://forums.androidcentral.com/samsu ... empty.html, and it may look like google did some changes some time after android 6, that makes the directory protected in some cases.

Now as a workaround, I did test to just use /mnt/sdcard as the path instead, which does seem to work on the three devices I have tested.

BTW. I miss an Android section at this forum. You do have the APK Compiler section,but as it is labeled today, it seemes to be for compiler issues only. The newly created Remedios section is labeled more generally to cover all iOS related stuff, perhaps the APK Compiler section could be labeled a similar way?

User avatar
airsoftsoftwair
Posts: 3219
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Makedir on SD card failed

Post by airsoftsoftwair » Tue Oct 01, 2019 12:20 am

Does it also happen when you compile your script as an applet and run it through the Hollywood Player?
BTW. I miss an Android section at this forum. You do have the APK Compiler section,but as it is labeled today, it seemes to be for compiler issues only. The newly created Remedios section is labeled more generally to cover all iOS related stuff, perhaps the APK Compiler section could be labeled a similar way?
Well, I don't have platform-specific forums so I don't want to break this rule because otherwise there'll be people asking for a macOS forum, a Windows forum, a Linux forum, etc. That's just too many...

amyren
Posts: 87
Joined: Thu May 02, 2019 11:53 am

Re: Makedir on SD card failed

Post by amyren » Tue Oct 01, 2019 10:43 am

Yes, it also happens with the player

User avatar
airsoftsoftwair
Posts: 3219
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Makedir on SD card failed

Post by airsoftsoftwair » Tue Oct 01, 2019 11:24 am

Please post a minimal (!) test script, the code in the original post seems like an excerpt from something bigger...

amyren
Posts: 87
Joined: Thu May 02, 2019 11:53 am

Re: Makedir on SD card failed

Post by amyren » Wed Oct 02, 2019 4:59 pm

airsoftsoftwair wrote:
Tue Oct 01, 2019 11:24 am
Please post a minimal (!) test script, the code in the original post seems like an excerpt from something bigger...
the code in the original post actually only need a couple of endif's to run. But here is an even smaller piece of code sufficient for testing

Code: Select all

If PermissionRequest(#PERMREQ_WRITEEXTERNAL)
	t = GetSystemInfo()
	MakeDirectory(t.SDCard.."/mydir")
EndIf

User avatar
airsoftsoftwair
Posts: 3219
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Makedir on SD card failed

Post by airsoftsoftwair » Tue Oct 15, 2019 3:36 pm

Ok, this is fixed now.

Code: Select all

- Fix [Android]: MakeDirectory() couldn't create directories when using absolute paths
As a workaround, just avoid using absolute paths, e.g.

Code: Select all

ChangeDirectory(t.SDCard)
MakeDirectory("mydir")

Post Reply