Skip to content

Directory list items ​

The DirListItem type represents a file or directory entry returned by directory listing functions in SyncJS.

ts
type DirListItem = {
  Name:      string;    // Fully qualified path and file name (e.g., "/docs/resume.docx")
  Type:      string;    // "FILE" or "DIR"
  Size:      number;    // File size in bytes
  TimeStamp: time.Time; // Timestamp of the item; use ToDate() to convert to JS Date
}

All functions that return directory lists provide an array of DirListItem objects.

You can use standard JavaScript methods to iterate over the array and access each item's properties.

NOTE

The TimeStamp property is a Go time.Time value. Pass it to the standalone ToDate() function to convert it to a JavaScript Date object for further manipulation.

Examples ​

Example 1: Iterating with a for loop ​

ts
// Acquire directory list
var dirList = cli.ListDir('/docs');
if (Array.isArray(dirList)) {
  for (var i = 0; i < dirList.length; i++) {
    Log(dirList[i].Name);
  }
}

Example 2: Iterating with forEach ​

ts
// Acquire directory list
var dirList = cli.ListDir('/docs');
if (Array.isArray(dirList)) {
  dirList.forEach(function(item, index, array) {
    Log(item.Name + ' [' + item.Size + ' bytes] [' + item.Type + ']');
  });
}