File Handling
BoxLang allows you to manipulate, read, upload, and more files via its built-in methods, which are great and easy to use. It can even help you manipulate zip/jar archives! We won't go into every single detail of file handling, but below, you can find the majority of functions to handle file handling.
You can find the file system functions here: https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/io.
DirectoryCopy
Copies the contents of a directory to a destination directory.DirectoryCreate
Creates a new directory for the specified pathDirectoryDelete
Deletes directory for a given pathDirectoryExists
Determines whether a directory exists.DirectoryList
Lists the directory and returns the list of files under it as an array or queryDirectoryRename
Renames given directoryExpandPath
Creates an absolute, platform-appropriate path that is equivalent to the value of relative_path, appended to the base path. This function (despite its name) can accept an absolute or relative path in the relative_path attributeFileAppend
appends the entire content to the specified file.FileClose
Closes an open file.FileCopy
Copies the specified on-disk or in-memory source file to the specified destination file.FileDelete
Deletes the specified file on the server.FileExists
Determines whether a file existsFileGetMimeType
Returns the mime type of the given fileFileInfo
returns detailed info about the given file.FileIsEOF
Determines whether BoxLang has reached the end of the file while reading it.FileMove
Moves file from source to destinationFileOpen
Opens a file to read, write, or append.FileRead
Reads an on-disk or in-memory text file or a file object created with the FileOpen function.FileReadLine
Reads a line from a file.FileSeek
Shifts the file pointer to the given position. The file must be opened with the seekable optionFileSetAccessMode
This function sets the attributes of an on-disk file on UNIX or Linux. It does not work with in-memory files.FileSetAttribute
For the given path, set the file attributes.FileSetLastModified
For the given file, set the last modification dateFileSkipBytes
Shifts the file pointer by the given number of bytes.FileTouch
Touches the given file and creates it if it does not already exist.FileUpload
Uploads a file to a directory on the server.FileUploadAll
Uploads files to a directory on the server.FileWrite
If you specify a file path, it writes the entire content to the specified file. If you specify a file object, it writes text or binary data to the file object.FileWriteLine
Opens up the file (or uses the existing file object) and appends the given line of textGetFileInfo
Retrieves file information.GetFreeSpace
Returns the number of unallocated bytes in the partition named by this abstract path name.GetTempDirectory
Returns the full path to the currently assigned temporary directoryGetTempFile
Creates a temporary file in a directory whose name starts with (at most) the first three characters of the prefix.ImageWrite
Writes an image to the specified filename or destination.
Dealing With Large Files
If you want to read or manipulate large files, we recommend leveraging our cbStreams library or native Java file streaming. Below, you can find some sample usage of reading large files with cbStreams, which implements the Java Streams API.
Last updated