File Operations
The File category provides file system operations that mirror the functionality of File nodes.
Available Functions
File.exists(path, useCache)- Checks if a file or directory existsFile.getFilesInFolder(folder, useCache)- Gets list of files in a folderFile.getFoldersInFolder(folder, useCache)- Gets list of folders in a folderFile.getChecksum(path, algorithm, useCache)- Calculates file checksumFile.saveText(path, content, useCache)- Saves text content to a fileFile.saveJson(path, data, useCache)- Saves data as JSON to a fileFile.loadText(path, useCache)- Loads text content from a fileFile.loadJson(path, useCache)- Loads JSON data from a file
Examples
Checking File Existence
if File.exists("config.json") then
Logger.info("Config file exists")
end
Listing Files and Folders
local files = File.getFilesInFolder("./data")
for i, file in ipairs(files) do
Logger.info("File: " .. file)
end
local folders = File.getFoldersInFolder("./data")
for i, folder in ipairs(folders) do
Logger.info("Folder: " .. folder)
end
File Checksum
local checksum = File.getChecksum("important.txt", "SHA256")
Logger.info("Checksum: " .. checksum)
Reading and Writing Files
-- Save text file
File.saveText("output.txt", "Hello World")
-- Load text file
local content = File.loadText("output.txt")
Logger.info("Content: " .. content)
-- Save JSON file
local data = {name = "John", age = 30}
File.saveJson("data.json", data)
-- Load JSON file
local loaded = File.loadJson("data.json")
Logger.info("Name: " .. loaded.name)
Parameters
path- File or directory path (relative to flow directory)folder- Folder path to listcontent- Text content to savedata- Data table to save as JSONalgorithm- Checksum algorithm (e.g., "SHA256", "MD5")useCache- Boolean, if true uses cache directory instead of flow directory
Return Values
existsreturns a booleangetFilesInFolder,getFoldersInFolderreturn arrays of stringsgetChecksumreturns a string (hexadecimal)loadTextreturns a stringloadJsonreturns a tablesaveText,saveJsonreturn boolean indicating success
Related Nodes
- FileExists Node
- GetFilesInFolder Node
- GetFoldersInFolder Node
- GetFileChecksum Node
- SaveToTextFile Node
- SaveToJsonFile Node
- LoadTextFile Node
- LoadJsonFile Node
Note
These functions work alongside the existing FlowFile API. Both are available for backward compatibility.