Example: Testing a file name

This JavaScript example demonstrates how to test whether or not a Service Manager file name in a string is valid. The script uses a string containing the file name to create a new SCFile object, and then tests the resulting object to see if it is valid. If the file name is valid, it contains the expected properties and methods (such as doSelect).

function testFile( fname )
{
  var undefined;

  var f = new SCFile( fname );

  if ( typeof f == "object" && f.doSelect != undefined )
  {
    print( fname + " is a real file!" );
  }
  else
    print( fname + " is NOT a real file!" );
}

testFile( "nonexistentfile" );

testFile( "contacts" );