Skip to content

GetCurrentVFS()

ts
function GetCurrentVFS(): VFS;

Returns a pointer to the current Virtual File System (VFS) object for the session, if available.

WARNING

The returned value may be null if the client session has started but no VFS has been selected yet. Always check for null before using the returned object.

Example

ts
var vfs = GetCurrentVFS();
if (vfs) {
  // We have a valid VFS object, so we can use it here
  var dir = vfs.ReadDir("/", "name", "asc");
  if (!dir.Ok()) {
    Log("ReadDir failed: " + dir.ErrorMsg());
  }
}

TIP

Some event-handlers (such as AfterFileUpload) are only triggered after a VFS has been selected. In these cases, the returned value from GetCurrentVFS() is guaranteed to be non-null, and you may skip the null-check.

Best Practices

  • Always check for null before using the returned VFS object, unless you are certain the event-handler guarantees a selected VFS.
  • Always check the result of VFS methods with Ok() before using their data, and handle errors appropriately.