Thread: MAKI Cheats
View Single Post
Old 20th February 2016, 00:02   #909
return wasabi;
(Forum King)
Plague's Avatar
Join Date: Jul 2001
Location: Sweden
Posts: 3,984
Local file path string handling in maki

Aight, so it's not exactly straight forward to do file handling in maki.
One problem is that backslashes in strings cannot easily be handled in maki.
For example, consider this path (which is what a path from getPlayItemString() would look like):

What if I want to get a string with only:
c:\music\artist1 ?

That's not easy.
getPath(getPlayItemString()) will only return:

We still need to remove:

Backslash is an escape character, so to search for a backslash in a string, one would normally have to write two backslashes: "\\".
But, the compiler will not compile the script if one tries to do that.
Another way is to look for the ASCII code for backslash: 92
But, if one tries to do a string search for Chr(92), it will return true for every single character in that string.
Not even getToken will work with backslash as separator.

However, there is one way to do it: urlEncode.
If we urlEncode the string, then every backslash will be replaced with: %5C
Now that we can search for.

So, here is a small script that finds the parent folder of the currently playing file:
PHP Code:
// get the complete path to the currently playing file.
string path getPath(getPlayItemString());
string parentpath "";

if (
strlen(path) > 0) {
// make sure the file is a local file by searching for "file:\\"
    // the backslashes in "file:\\" are not included in this search, because the script will not compile with them included.
    // we still need to remove the backslashes later however.
int start strsearch(path"file:");
    if (
start > -1) {
// the 7 is the number of characters to remove ( file:\\ )
        // we must urlEncode the string, because we cannot search for a single backslash otherwise
path urlEncode(strright(pathstrlen(path) - (start 7)));
int i strlen(path) - 1;
        while (
> -1) {
// search for the last backslash ( %5C ) position.
            // we urlDecode all text before that position.
            // the parentpath will then be that decoded text.
if (getToken(strright(pathstrlen(path) - i), "%5C"1) != "") {
parentpath urlDecode(strleft(pathi));

if (
parentpath != "") {
// do stuff
    // this messagebox will show the parent folder path

Plague is offline   Reply With Quote