SetFolder

Description

In normal use only two folders are accessible to your AGK app; the read folder and the write folder. The read folder is the location of your executable and includes the media folder. The write folder (which also has read permission), is located in a platform safe location and is different depending on the device. On Windows, for example, the default write location is C:\Users\username\AppData\AGKApps\appName (By default this is a hidden folder on Windows and you may have to show hidden files to see it). These are your root folders. Any files created/written using OpenToWrite will be saved into the write folder.

For simplicity, AGK merges these two read and write folders into a single command set. What this means is that when you attempt to open or load a file, AGK will first look in the write folder before looking in the read folder.

When using SetFolder, its behavior is what you'd expect from the CD command in the Windows console; It works from the current directory. For instance, if the current read folder is C:\games\myApp\ then SetFolder("images") will put you in C:\games\myApp\images. Calling the command a second time with SetFolder("backgrounds") will place you at C:\games\myApp\images\backgrounds\.

There are two ways to return to the base path. The first is to call SetFolder("") using an empty string. The other is to precede your path with a forward slash, SetFolder("/stuff"). This also applies to loading your files with other commands as well. Assume you're still located in the images\backgrounds folders and you want to load bk.png located in the base of the read folder. You can simply say LoadImage("/bk.png") which will load C:\games\myApp\bk.png.

Setting the path to a folder that does not exist and using OpenToWrite will create that folder in the write path. SetFolder does not check that the folder exists, it just sets an internal path that will be used in the next file command. By default, AGK calls SetFolder("media") as the first thing it does.

This command returns 1 on success or 0 if you use an invalid path such as SetFolder("C:\").

Note: It is important to remember when setting paths to always use forward slashes instead of backslash. AGK will convert them into the appropriate file separator for the given platform.

If you want to access files outside of the read and write folders you can use the normal file commands such as OpenToRead with a "raw:" file path, see that command for more details. To access folders outside the read and write folders you can use the OpenRawFolder commands.

Definition

integer SetFolder( str )

Parameters