File

Description

Supported Script Types: Interface Scripts • Client Entity Scripts • Avatar Scripts • Server Entity Scripts • Assignment Client Scripts

The File API provides some facilities for working with the file system.

Methods

Name Return Value Summary
convertUrlToPath string

Extracts a filename from a URL, where the filename is specified in the query part of the URL as filename=.

getTempDir string

Creates a new, unique directory for temporary use.

runUnzip None

Unzips a file in the local file system to a new, unique temporary directory.

Signals

Name Summary
unzipResult

Triggered when runUnzip completes.

Method Details

(static) convertUrlToPath( url ) → {string}
Returns: The filename specified in the URL; an empty string if no filename is specified.

Extracts a filename from a URL, where the filename is specified in the query part of the URL as filename=.

Parameters

Name Type Description
url string

The URL to extract the filename from.

Example

Extract a filename from a URL.

var url = "http://domain.tld/path/page.html?filename=file.ext";
print("File name: " + File.convertUrlToPath(url));  // file.ext
(static) getTempDir( ) → {string}
Returns: The path of the newly created temporary directory.

Creates a new, unique directory for temporary use.

Example

Create a temporary directory.

print("New temporary directory: " + File.getTempDir());
(static) runUnzip( path, url, autoAdd, isZip, isBlocks )

Unzips a file in the local file system to a new, unique temporary directory.

Parameters

Name Type Description
path string

The path of the zip file in the local file system. May have a leading "file:///". Need not have a ".zip" extension if it is in a temporary directory (as created by getTempDir).

url string

Not used.

autoAdd boolean

Not used by user scripts. The value is simply passed through to the unzipResult signal.

isZip boolean

Set to true if path has a ".zip" extension, false if it doesn't (but should still be treated as a zip file).

isBlocks boolean

Not used by user scripts. The value is simply passed through to the unzipResult signal.

Example

Select and unzip a file.

File.unzipResult.connect(function (zipFile, unzipFiles, autoAdd, isZip, isBlocks) {
    print("File.unzipResult()");
    print("- zipFile: " + zipFile);
    print("- unzipFiles(" + unzipFiles.length + "): " + unzipFiles);
    print("- autoAdd: " + autoAdd);
    print("- isZip: " + isZip);
    print("- isBlocks: " + isBlocks);
});

var zipFile = Window.browse("Select a Zip File", "", "*.zip");
if (zipFile) {
    File.runUnzip(zipFile, "", false, true, false);
} else {
    print("Zip file not selected.");
}

Signal Details

unzipResult( zipFile, unzipFiles, autoAdd, isZip, isBlocks )
Returns: Signal

Triggered when runUnzip completes.

Parameters

Name Type Description
zipFile string

The file that was unzipped.

unzipFiles Array.<string>

The paths of the unzipped files in a newly created temporary directory. Includes entries for any subdirectories created. An empty array if the zipFile could not be unzipped.

autoAdd boolean

The value that runUnzip was called with.

isZip boolean

true if runUnzip was called with isZip == true, unless there is no FBX or OBJ file in the unzipped file(s) in which case the value is false.

isBlocks boolean

The value that runUnzip was called with.