Skip to content

FileInfo / SearchFolderOptions — k.file ​

File and folder metadata objects and folder search options for k.file

Execution ContextPrerequisitesTypical Use
Server-side KScript (k.api, <script env="server">, scheduled jobs)Returned by k.file methods or passed into k.file.folderFiles()Inspect file sizes, URLs, and timestamps, and filter recursive folder listings

Quick Start ​

Read FileInfo metadata via k.file.get(), and filter k.file.folderFiles() using SearchFolderOptions:

js
k.api.get(() => {
    const info = k.file.get("uploads/report.txt")
    const matched = k.file.folderFiles("uploads", {
        includeAllDirectories: true,
        searchPattern: "*.txt"
    })
    return {
        file: info ? { name: info.name, size: info.size, url: info.relativeUrl } : null,
        matchedNames: matched.map((item) => item.fullName)
    }
})

Quick Reference ​

Method / PropertyDescriptionReturns
FileInfoFile metadata object returned by write, writeBinary, get, load, folderFiles, getAllFiles, and buildFileInfo
FolderInfoFolder name and full path object returned by subFolders()FolderInfo
SearchFolderOptionsOptional search filter (searchPattern, recursion, author) passed to k.file.folderFiles()SearchFolderOptions

FileInfo Property ​

PropertyDescriptionType
nameFile namestring
fullNameFull storage pathstring
sizeFile size (bytes)number
stringSizeFormatted file size stringstring
relativeUrlRelative URLstring
absoluteUrlAbsolute URLstring
urlAccess URL (same as relativeUrl)string
lastModifiedLast modified timeDate
authorUserNameAuthor usernamestring

FolderInfo Property ​

PropertyDescriptionType
nameFolder namestring
fullNameFull folder pathstring

SearchFolderOptions Property ​

PropertyDescriptionType
includeAuthorWhether to include author informationboolean
includeAllDirectoriesWhether to include all subdirectories recursivelyboolean
searchPatternSearch pattern, defaults to *.*string

TypeScript Definitions ​

ts
interface FileInfo {
  name: string;
  fullName: string;
  size: number;
  stringSize: string;
  relativeUrl: string;
  absoluteUrl: string;
  url: string;
  lastModified: Date;
  authorUserName: string;
}

interface FolderInfo {
  name: string;
  fullName: string;
}

interface SearchFolderOptions {
  includeAuthor?: boolean;
  includeAllDirectories?: boolean;
  searchPattern?: string;
}