GMLscripts.com

Discuss and collaborate on GML scripts
Invert

You are not logged in.

#1 2010-10-02 14:51:13

Marchal_Mig12
Member
Registered: 2009-05-21
Posts: 75

directory_create_missing

Hi everyone, here's my contribution to gmlscripts: directory_create_missing. The script is fairly easy to understand. What it does is creating every missing directory in a given path. For example, in a game, if you want to let the user to create screenshot and you want to store them in a multi-directory path such as: /Data/Screenshot/Zerg/. This works fine if the directory are already there but what happens if the user deleted those? Game Maker will throw an error. What I did for my game for online sharing maps that has to be stored in custom directories, I created a script that will create the directories which will allow anything to be stored in a given path even thought the directories did not exists.

Here's the script finally:

Expand//arg0: Path
var fname, directory, i;
fname = string_replace_all(argument0,"\","/");
directory = "";

i = 0;
repeat(string_count("/",fname))
{
  directory += "/"+reflect_nextvar(fname,i,"/");
  if not directory_exists(working_directory+directory) then
    directory_create(working_directory+directory);
  i += 1;
}

However, the script uses another script which Fred from the Reflect community provided me. Here's his script:

Expand//retrieve values from a list of values seperated by the character  designated in argument 2
//returns the value if it exists, and a blank string if it does not

//  argument list
//  0 - input string
//  1 - position of the variable in the string (starting at 0)
//  2 - the character that seperates values from one another ("," "|" etc.)

var temp_index,input_string,temp_string,i;
input_string = argument0;
temp_index = argument1;
search_char = argument2;

for(i=0;i<=temp_index;i+=1) {
    if(string_pos(search_char,input_string) != 0) {
        temp_string = string_copy(input_string,1,string_pos(search_char,input_string)-1);
    } else {
        temp_string = input_string;
    }
    input_string = string_delete(input_string,1,string_length(temp_string)+string_length(search_char));
}

return temp_string;

Hope you like it. We can now make sure it is 100% liable and then format it correctly to finally release it wink.

Miguel

Offline

#2 2010-10-03 00:33:57

icuurd12b42
Member
Registered: 2008-12-11
Posts: 303

Re: directory_create_missing

It's very useful for installing files. working_directory forces it to only be done in the game folder, which may be a good thing for noobs. we can aleways remove that. good job

Offline

#3 2010-10-04 19:25:46

xot
Administrator
Registered: 2007-08-18
Posts: 1,240

Re: directory_create_missing

This is a really good idea for a script.

That second script from Fred is a simpler version of an existing script here: string_parse_single

It could be substituted for Fred's, but I wonder if it would be worth the effort to just merge the everything into a single directory creation script.


Abusing forum power since 1986.

Offline

#4 2010-10-05 12:00:57

Marchal_Mig12
Member
Registered: 2009-05-21
Posts: 75

Re: directory_create_missing

Thanks! As for the working_directory part, we could always remove that as you said icuurd12b42. And as for your suggestions, xot, I'll look into it and make some tests wink. OR we could always make people use the script already on the website.

I'll post the updated script soon.

Offline

Board footer

Powered by FluxBB