Game Development Community

Execute script files in directories and subdirectories

by Ronald J Nelson · in Torque Game Engine · 09/17/2007 (5:32 pm) · 4 replies

Basically, I had a function to do this once. I lost it and need it again. I am hoping someone could just throw me a quick script function for it.

#1
09/17/2007 (6:08 pm)
Are you needing exec("FILEPATH/SCRIPTFILE.cs");?

Or the one that sets which directories will be visible to the scripts and the resource engine? setModPaths(string path);
#2
09/18/2007 (2:33 am)
Sounds to me like he wants to execute all the scripts in and under a specific folder..

This is off the top of my head so forgive me if its not quite right..
function execAll(%root)
{
   %fileSpec = %root @ "/*.cs";
   %file = findFirstFile(%fileSpec);
   for(; %file !$= ""; %file = findNextFile(%fileSpec)) 
   { 
      exec(%file);
   }
}

Call like: execAll("~/client");
#3
09/18/2007 (2:43 am)
I use something like this to execute a bunch of script files within a single folder:
// This function will execute all *.cs scripts
   // that are placed in the server/scripts/weapons folder.

   %search = "./weapons/*.cs";

   for(%file = findFirstFile(%search); %file !$= ""; %file = findNextFile(%search))
   {
      %type = fileBase(%file); // get the name of the script
   	  exec("./weapons/" @ %type @ ".cs");
   }

Does that help?
#4
09/18/2007 (5:14 am)
Thanks all.