Author Topic: Checking file names.  (Read 1142 times)

How would you check for file names like the add-on list?

dumpConsoleFunctions(); returns these:

Code: [Select]
   /*!  Returns the first file in the directory system matching the given pattern. */
   virtual string findFirstFile(string pattern) {}
   /*!  Returns the next file matching a search begun in findFirstFile. */
   virtual string findNextFile(string pattern) {}
   /*! returns the number of files in the directory tree that match the given pattern */
   virtual int getFileCount(string pattern) {}
(...)
   virtual bool isFile(fileName) {}
(...)
   virtual bool isWriteableFileName(fileName) {}
   virtual string fileExt(fileName) {} (Space Guy: Returns extension i.e. ".cs" of file name)
   virtual string fileBase(fileName) {} (Returns file string i.e. "Weapon_Gun.cs")
   virtual string fileName(filePathName) {} (Returns file name i.e. "Weapon_Gun")
   virtual string filePath(fileName) {} (Retunrs file path i.e. "Add-ons" or "Add-ons/client"

Code: [Select]
function getFiles()
{
 %arrayCount = 0;
 %array[0] = "";
 %file = findFirstFile("Add-Ons/*.cs");
 echo("****Begin File Loading****");
 if(%file $= ""){error("ERROR: No Files. Aborting...");return;}
 while(%file !$= "")
 {
  %array[%arrayCount++] = %file;
  %file = findNextFile("Add-Ons/*.cs");
  echo(%file," (",fileName(%file),")");
 }
 echo("****End File Loading****");
}
Loops through all of Add-Ons finding any .cs file. An array, "%array[%arrayCount]" is made. Anything you want to do with the files has to be in this function because %array is erased after the function ends.

The array contains things like:
Add-Ons/Weapon_Gun.cs

The echo();s will return:
Quote
****Begin File Loading****
Add-Ons/Weapon_Gun.cs (Weapon_Gun.cs)
Add-Ons/Client/RPGBinds.cs (RPGBinds.cs)
****End File Loading****
« Last Edit: June 30, 2007, 03:44:53 AM by Space Guy »