Organizing DirAssets

pixelpop

Active Member
Licensed User
Longtime User
Is it possible to organize the contents of DirAssets into sub-folders? If it is, how would a file called JFK.JPG in a folder called MAPS within the DirAssets folder be called, as in LoadBitmap(File.DirAssets,"JFK.PNG")
 

pixelpop

Active Member
Licensed User
Longtime User
Thanks, Erel. That also answers a question that I put in the Wishes/Bugs forum about file naming.
 
Upvote 0

Sarah

Member
Licensed User
Longtime User
This works perfectly when you need to access a file in a sub-folder of DirAssets but I am unable to check that such a file exists.
I have a routine that uses a file that could be in DirInternal or in DirAssets, so I need to test whether the file exists in either place.

All of these return false, even though I can play the sound file:
B4X:
File.Exists(File.DirAssets, "audio/test.wav")
File.Exists(File.DirAssets, "audio\test.wav")
File.Exists(File.DirAssets & "/audio", "test.wav")
File.Exists(File.DirAssets & "\audio", "test.wav")

Note that for accessing the file, using forward slash works fine (I am used to Mac & Linux systems, so I always use /).
So I guess they are interchangeable.
 
Upvote 0

Sarah

Member
Licensed User
Longtime User
File.Exists currently doesn't work with subfolders in the assets folder. However you are putting the files there so you should be able to know whether a specific file exists or not.

Yes, that is what I have gone with in the end.
Just paranoia on my part - I always like to check for the existence of a file before trying to use it :)
 
Upvote 0

Sarah

Member
Licensed User
Longtime User
I presume that File.ListFiles(File.DirAssets & "/sub") failing is the same issue.
Is this something that is likely to be added?

I need to iterate over the files, so I guess I will have to list them in the app & iterate that way.
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
Just to add a comment to this oldish thread.

If you use sub-folders in the Files folder and export your project, then the exported project will NOT contain those sub-folders.

Martin.
 
  • Like
Reactions: eps
Upvote 0

TheWind777

Active Member
Licensed User
Longtime User
That is correct. It may be added in the future. Though you do not need to check for existence of files added to the Files tab. They will be there.

Well, I've run across a strange one. It's a simple subroutine:


B4X:
sub Globals

Dim gif As GifDecoder

end sub

If File.Exists(File.DirAssets,"dino.gif") Then

    Log("About_Sub - dino.gif does exist; loading 'dino.gif'")

Try

  gif.Load(File.DirAssets, "dino.gif")

Catch

     Log("About_Sub - Couldn't Load dino.gif for unknown reasons.")

  ABOUT_COULD_NOT_LOAD_GIF = True
EndTry

EndIf

When I run it, it dies with a 'Can't find file'.

I then added code which copied the dino.gif file to DirDefaultExternal, tried loading it from there... and it works.

Why would I check for a file in the DirAssets folder, it says it is there. Then when it tries to use it for the GifDecoder library - not work if the file is in the DirAssets folder but work if the very same file is copied over to the DirDefaultExternal directory?

I thought maybe there was something corrupted in the Files or Objects folders; so I created a new Project, copied all things over to the new project. Did the same thing.

I would say that the DirAssets folder, it self, must have the wrong Permissions set on it, or something? Is there a way that I can have it delete the DirAssets folder completely and rebuild it? Or, is there some other thing that you can think of that would account for such a strange thing?

The GifDecoder.Load function just wants two strings to be passed to it, the Dir as a string, the text file name as a string.

The thing that is annoying is that most of the time it was working just fine. Only recently does it not allow the picture to be loaded.

The only thing I can think of would be that the function is being called twice, somehow? And so the GifDecoder Gif variable of type GifDecoder is already locked, so it can't load it again? Or, somehow the system has put a lock on the file, not released the lock, and thus doesn't let it do it again?

I'm stumped.

If the GifDecoder library was asking for a BitMap object, or something other than just two Strings, I would not be so stumped.

The fact that it has worked before, and just isn't working right now, also stumps me.

Any ideas? Why would it work if I copied the file to the DirDefaultExternal folder, but not if I try loading it from the DirAssets folder?

Where IS the DirAssets folder, anyways? I can't check to see what permissions it might have (although it's just reading the file, not writing the file, so why would permissions have anything to do with it?)

Picking at straws because I can't imagine a possibility.

As usual, the program is just too huge to send 30MB now. Hoping that something you know will jog me towards the right outcome. I guess I could just copy the file over to the DirDefaultExternal folder and always run it from there - but hate to allow strange things that are occurring to continue. That almost always runs into problems later down the road.
 
Upvote 0

KMatle

Expert
Licensed User
Longtime User
Keep in mind that File.DirAssets and it's contents is a "known" folder to the developer. It makes no sense to me to check if a file is there because it's not changable at runtime and contains only files you've put there.

Take a look at the libgdx examples. They use a lot of subfolders to organize :)
 
Upvote 0

TheWind777

Active Member
Licensed User
Longtime User
Well, I know that it is supposed to be there. And, the check for the file says it is there; but when it loads it it is not there.

When you copy it to the External default it works fine.

Of course I'm going to do a check for it because it is saying it is not there and am trying to figure out why it is not finding it.

I also listed the directory by using a different method and the file was there.

So, why is it not being able to load the file? Is there some way of seeing more information about the error that is occurring using some error library, or something?
 
Upvote 0

TheWind777

Active Member
Licensed User
Longtime User
Keep in mind that File.DirAssets and it's contents is a "known" folder to the developer. It makes no sense to me to check if a file is there because it's not changable at runtime and contains only files you've put there.

Take a look at the libgdx examples. They use a lot of subfolders to organize :)

Well, I know that it is supposed to be there. And, the check for the file says it is there; but when it loads it it is not there.

When you copy it to the External default it works fine.

Of course I'm going to do a check for it because it is saying it is not there and am trying to figure out why it is not finding it.

I also listed the directory by using a different method and the file was there.

So, why is it not being able to load the file? Is there some way of seeing more information about the error that is occurring using some error library, or something?

Other strange things occur that I can't figure out.

Sometimes it goes into pause mode without the window going away. Panel is still visible, yet it is in pause mode.

Sometimes it seems like it doesn't load the global variables.

I have seen it go into pause mode without a resume having occurred, and proved it by setting a flag.

I have seen it go into resume mode without a pause having been done and proved it by setting a flag.

I suspect that the problem is something that I'm initializing in the wrong place (initializing in Globals when should be initialized in Create, or initialized in create when should be initialized in create -> firsttime, etc. but can't be sure.

I have tried strict mode... but then don't know how ones views the logs that are written.

I've been stuck with bad errors happening for quite some time now. It has been frustrating because my protection schemes and checks to make sure things are there are far more stringent than most people's ever are.

I have been frustrated for quite some time... hitting my head into brick walls which make no sense.

The overall program works perfectly, until it doesn't. Then it goes off into really strange tangents and blows-up.

I'm sure it is related to my need to force the Overlord Service Module to never be unloaded. It has to be its own program, and has to constantly and continually be checking the time. To keep the system from killing the process, I turn on FRONT mode, but it seems that bringing it to the front causes a Pause and Resume of the Activity, which is annoying because I suspect that it is doing the resume in the middle of such things as my Activity loading Global Variables.

When I turn off the Overlord and never load the service module, the problem goes away.

In fact, I think it might be kicking off a Pause/Resume TWICE when the Service module is created, and again when it is put into Front mode.

What are the particulars of what Resume/Pause things occur when a service module is created?
 
Upvote 0
Top