DWScript provides simple functions for reading, writing, and managing files and directories.
For most tasks, FileRead and FileWrite are the easiest way to handle file content as strings. If you need to process a file line by line, FileReadLines returns an array of strings.
var content := 'Hello from DWScript';
FileWrite('test.txt', content);
var read := FileRead('test.txt');
PrintLn(read);
// Process line by line
var lines := FileReadLines('test.txt');
for var line in lines do
PrintLn('> ' + line);
DeleteFile('test.txt'); Hello from DWScript > Hello from DWScript
Listing files is done using EnumerateDir, which returns an array of strings.
var files := EnumerateDir('lang/basics', 'intro*.md', False);
if files.Length > 0 then
PrintLn('Found documentation'); Found documentation
Functions like ExtractFileName and ChangeFileExt help you manage file paths without manually parsing strings.
var path := 'C:\Data\User.json';
PrintLn(ExtractFileName(path)); // User.json
PrintLn(ExtractFilePath(path)); // C:\Data\
PrintLn(ChangeFileExt(path, '.bak')); // C:\Data\User.bak User.json C:\Data\ C:\Data\User.bak
For a complete list of all I/O functions and directory utilities, see the reference documentation:
.ini configuration files.