File System Access (XSISDK)

This topic discusses general issues related to reading the file system from scripts. See also: JScript (XSISDK)#File System Access

Note: For C++ file access check out the C stdio library (fopen/fread) or other freely available file IO libraries.

See also "Writing Toolbar files with Scripting".

File System Object Model

JScript and VBScript script code have access to a built-in (non-Softimage) object named FileSystemObject. It in turn offers a whole File-oriented object model, with objects for Folders (Directories), Files and Drives. This can be used to read what files are on disk, recursively search folders, open and write text files etc.

Python and Perl include powerful built-in libraries for file access, so it is unlikely that they would use the FileSystemObject (although it is available).


Created Scripting.FileSystemObject

The best API for creating an instance of this object is XSIFactory.CreateActiveXObject.

'VBScript
set oFSO = XSIFactory.CreateActiveXObject( "Scripting.FileSystemObject" ) 


'JScript
var oFSO = XSIFactory.CreateActiveXObject( "Scripting.FileSystemObject" ) ;


In the context of Net View the XSIFactory object is not immediately available as a global variable, but a helper function like this can easily be used to create the Scripting.FileSystemObject.

// JScript Netview helper
function SafeCreateObject( in_ProgID ) {
	 
 	var xsifactory, oObj;
	try {
		//First create our ActiveX (which is marked as safe) 
		xsifactory = new ActiveXObject("XSI.Factory"); 
 
		//Use xsifactory to create the object 
		oObj = xsifactory.CreateActiveXObject(in_ProgID); 
	}
	catch (e) {
		//Problem might be that user is running an older version of XSI, so try the old 
		//version (this method might pop a ActiveX warning dialog) 
		
 		alert("SafeCreateObject: "+ e.description);
		e.clear;
		oObj = new ActiveXObject( in_ProgID ); 
	} 

	return oObj; 
 }

Cross Platform Path Manipulation

Starting with v.5.0, XSI offers XSIUtils.BuildPath(), XSIUtils.Slash and XSIUtils.IsFileSystemCaseSensitive to help write script code that works on both Linux (which is case sensitive and uses the / character as path seperator) and Windows (case insensitive using the \ character).

Travelling through directories and files using an Object Model such as the FileSystemObject also tends to be cross platform.

Some scripts might get away with using the "/" character as a path separator on both platforms. However, Windows only partially supports that so it is better to use XSIUtils.Slash.


This page was last modified 12:35, 30 Aug 2007.
This page has been accessed 14694 times.

© Copyright 2009 Autodesk Inc. All Rights Reserved. Privacy Policy | Legal Notices and Trademarks | Report Piracy