Skip to content

File IO

Nenkai edited this page Jul 14, 2024 · 7 revisions

Warning

This API was introduced after GT4.

Check file exists

if (pdistd::ReadFile(path))
{
    // File exists
}

Reading Files

var st = main::pdistd::ReadFile(path);
if (st["result"] == pdistd::FileError::OK)
{
    var buf = st["buffer"];
    // Do something with the buffer...
}

Writing Files

var str = "hello";
if (pdistd::WriteFile(path, str))
{
    // ...
}

Get File Info

var st = pdistd::GetFileStatus(path);
st["result"] // Result
st["size"] // File Size
st["_time"] // Datetime

Listing Directory Files

var files = pdistd::GetFileEntries(dir);
if (files == nil)
   return;

foreach (var file in files)
{
    var is_dir = entry["type"] == "DIRECTORY";
    var is_file = entry["type"] == "REGULAR";
    // ...
}

Creating/Copying/Removing Files/Directories

pdistd::MakeDirectory(dir, recursive);
pdistd::MakeDirectoryForFile(file_path);
pdistd::CopyFile(source, destination);
pdistd::RemoveFile(file);
pdistd::RemoveDirectory(directory, true); // second argument is recursive.

Get Disk/Mount Free Size

var size_left = pdistd::GetDiskFreeSize(path);
Clone this wiki locally