Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / SetFolder() and GetFirstFile() - what's going on there?

Author
Message
Scraggle
Moderator
21
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 18th Feb 2016 14:54
Hi,

I'm trying to create a list of images in my folders.
It seems like a pretty straight forward task but it is proving very tricky indeed.

This is my file reading function:


and the calling code:


If I call CreateImageList( imgList, "" ) with an empty string, I get a list of the default images in an AppGameKit project (virtual joystick etc.) and the folder path is printed as blank
If I call CreateImageList( imgList, "media" ) then I would expect to get a list of all images in the media folder but no, I get nothing and the folder path is now printed as media/media

If I create a subfolder called media/media then the above code reads it but what I want to do is read the media folder.
How am I supposed to do that?

AGK V2 user - Tier 1 (mostly)
Battoad
AGK Developer
17
Years of Service
User Offline
Joined: 12th Feb 2007
Location: A Dark Place
Posted: 18th Feb 2016 15:19
Hi Scraggle, it sounds like you have put your images in a folder, named media, and put that media folder in the default media folder.
So when you search for files in the default media folder, there aren't any, only another media folder.

If you change directory to the media folder which holds your images, then the files will be found.
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 18th Feb 2016 15:42 Edited at: 18th Feb 2016 15:43
SetFolder will set the folder to the current folder plus whatever's in the path. (The default folder IS the media folder)

If you want to read another folder then the media folder, or just to be sure, try SetFolder "" : SetFolder Path$ as two statements.
This will reset the working folder to the one holding the bytecode, then move to the media folder.
Scraggle
Moderator
21
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 18th Feb 2016 15:51 Edited at: 18th Feb 2016 15:52
Quote: "Hi Scraggle, it sounds like you have put your images in a folder, named media, and put that media folder in the default media folder."

It does sound like that doesn't it?
That's definitely not the case though. I have a root project folder with a media folder in it. No other folders.

This is intriguing though:
Quote: "This will reset the working folder to the one holding the bytecode, then move to the media folder."

My bytecode is in my media folder. Are you suggesting that it should be in the root project folder?
If I delete it, then it gets written in the media folder again.
AGK V2 user - Tier 1 (mostly)
Scraggle
Moderator
21
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 18th Feb 2016 16:09 Edited at: 18th Feb 2016 16:10
There are some very strange things afoot!

If I change my calling code to CreateImageList( imgList, "media/.." ) (media folder and then back up one) I get a list of all the images in my media folder but (and it's a BIG but) that means that juney's theory is correct and I do have a media folder inside a media folder. The problem with that is that it isn't true!
The code says it has to be true be reality says it isn't - what the fudge is going on?

Just to prove I'm not going mad, here is my project folder:


And this is my media folder:
AGK V2 user - Tier 1 (mostly)
Battoad
AGK Developer
17
Years of Service
User Offline
Joined: 12th Feb 2007
Location: A Dark Place
Posted: 18th Feb 2016 16:25
Quote: "If I call CreateImageList( imgList, "" ) with an empty string, I get a list of the default images in an AppGameKit project (virtual joystick etc.) and the folder path is printed as blank"

Unfortunately when in the root project directory it does not provide the folder name. Even though a blank is returned, this is correct. Its only when you are not in the root folder that a folder name is shown.

Quote: " try SetFolder "" "

Yes I am sure Mobiius is right. Just add the line SetFolder("") the line before SetFolder(d$) and I believe it should work.
Scraggle
Moderator
21
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 18th Feb 2016 16:29
I managed to overlook that tip but yes, it works!
And now that I've thought about it, it makes perfect sense too.

Thanks guys
AGK V2 user - Tier 1 (mostly)
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 18th Feb 2016 16:31 Edited at: 18th Feb 2016 16:35
I avoid all headaches by always setting the folder from the root, by preceding with a "/"
For my media folder...
Setfolder("/media/")
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 18th Feb 2016 16:37
Quote: "I avoid all headaches by always setting the folder from the root, by preceding with a "/"
For my media folder...
Setfolder("/[color]media/")[/color][/b]"

Or you could do this, but I've found that sometimes this doesn't work, as calling setfolder( "/media/other/" ), will change the folder to teh other folder. So then calling setfolder( "/media/more other/" ) will actually try to put you into media/media/more other
hakimfullmetal
9
Years of Service
User Offline
Joined: 17th Feb 2015
Location:
Posted: 18th Feb 2016 17:08 Edited at: 18th Feb 2016 17:11
Not sure if this would help, but this is what Paul did to set up folders for correct reading from the intended folders:
The act of calling the SetFolder("") with an empty string is very important.
We had to call it whenever we want to set a new folder for reading.



Just in case:

Quote: "
We had to call the SetFolder("") with an empty string for the other commands to 'read' from the 'write' file.
It's more like an unfortunate side affect. By default the folder is set with SetFolder("/media") when the app starts running, so in this case GetFirstFolder() would be looking in E:\Temp\media. If you are using other load commands then you can work around this by forcing the path to root by using LoadImage("/myimage.png") which will ignore the SetFolder part of the path. Or LoadImage("/media/myimage.png") to load it from the media folder whilst SetFolder is set to the empty string.

The GetFirstFile and GetFirstFolder commands collate results from both the read and write folder into a single list. In this case the write folder is listed first and then the read folder. Duplicate file and folder names will only appear once in the list.
"
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 18th Feb 2016 18:06
I answered a similar question earlier today, with sample code. It illustrates how precise you need to be to get it to work just right...

http://steamcommunity.com/app/325180/discussions/0/405692224222035855/
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Scraggle
Moderator
21
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 18th Feb 2016 18:49
That's a lovely little recursive function you've written there BatVink.
It's a crying shame it can't be used on the media folder though because that is where it would be put to best use
AGK V2 user - Tier 1 (mostly)
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 19th Feb 2016 09:09
If you swap out GetRawWritePath for SetFolder, it should work.
The issue with the media folder, is if you are trying to iterate through folders outside of your app folder. Then , it combines the two and causes issues with folders that have the same names as folders in your app folder.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Dybing
13
Years of Service
User Offline
Joined: 12th Sep 2011
Location: Bergen, Norway
Posted: 19th Feb 2016 14:45
As BatVink say, if having multiple folders navigate through them using SetFolder "/{your folder name}"

The first argument - the forward slash - tell your program to go up one level in your file-tree. If already in project root, it does nothing. The next argument, tells which folder folder you want to read a file from or write a file to. If you are to simply read a file, just make sure it is present in the given folder - to avoid getting an error, load the file inside a if getFileExists("{file-name}") = 1 check.

If writing a file, you won't see the resulting file in your project sub-folder. It'll be saved (in windows) under {your account name}/AppData/Local/AGKApps/{your projects name}/{your projects subfolder}

In Windows, you can write to wherever you want, by using the Raw file-commands. But unless you got some special reason to do so, I'd just avoid doing it. For one thing you need be very careful keeping track on where in your file-structure the raw commands point to, and for another it makes your app incompatible with other OSes, like Android and iOS.

Login to post a reply

Server time is: 2024-09-29 11:30:35
Your offset time is: 2024-09-29 11:30:35