TFile.Exists

From Soldat Community Wiki
Revision as of 17:05, 29 July 2013 by Menturi (talk | contribs) (Example: Removed invalid semicolon)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
function Exists(const Source: string): Boolean
 Source: a path to a file to check access for
 Result: Whenever file exists or not

Description

This function checks whenever file pointed by Source exists on hard drive. If the path is out of script's sandbox, EAccessViolation exception is thrown.

Example

procedure OnPlayerCommand(Player: TActivePlayer; Text: string);
begin
  // Assuming config Sandboxed=2 (default)
  Delete(Text, 1, 1); // remove command's slash
  try
    if File.Exists('~/' + Text + '.ini') then
      Player.WriteConsole('Yup, config for that map exists', $FFFFFFFF)
    else
      Player.WriteConsole('Sorry, this config for this map doesn''t exist', $FFFFFFFF);
  except    
    Player.WriteConsole('Wrong path (you added ../ a few times, didn''t you?)', $FFFFFFFF);
  end;
end;