-
Notifications
You must be signed in to change notification settings - Fork 0
GDDirectory
BelicusBr edited this page Sep 7, 2024
·
4 revisions
The GDDirectory
class obtains all or part of the directories present in the game.
Properties | Description |
---|---|
string GDFileBase.Path | Gets the full path of the file or directory. |
string GDFileBase.Name | Gets the name of the file or directory. |
int GDDirectory.Count | Gets the subdirectory number. |
GDFileBase GDFileBase.Parent | Gets the parent directory. |
GDFileAttributes GDFileBase.Attribute | Gets the attribute of the file or directory. |
string GDFileBase.NameWithoutExtension | Gets the name without the file extension. |
Methods | Description |
---|---|
static GDDirectory GDDirectory.GetGDDirectory() | Gets the res:// directory. The res:// directory is the game's root directory. |
static GDDirectory GDDirectory.GetGDDirectory(string) | Gets the specified directory.(example: res://folder, user://folder, C://temp/folder) |
GDFile GDDirectory.GetFile(string, bool:false) | Gets a specific file in the directory. |
GDFile[] GDDirectory.GetFiles(bool:false) | Gets all files in the directory. |
GDDirectory[] GDDirectory.GetDirectories() | Gets all subdirectories of the directory. |
bool GDDirectory.RemoveFile(string) | Removes the specified file from the directory. |
bool GDDirectory.RemoveDirectory(string) | Removes the specified subdirectory in the directory. |
GDDirectory GDDirectory.GetDirectory(string, bool:false) | Gets all subdirectories specified in the directory. |
Gets the res:// directory. The res:// directory is the game's root directory.
public static void MainTest() {
using (GDDirectory dir = GDDirectory.GetGDDirectory()) {
//Here you can enter the file name with or without the extension.
//filetest or filetest.txt
GDFile file = dir.GetFile("filetest");
if (file != null)
GD.Print(file.Read());
}
}
The GDFile
class represents the file.
Methods | Description |
---|---|
string GDFile.Read() | File reading method. |
void GDFile.Write(byte[]) | File writing method. |
Resource GDFile.Load() | Allows you to upload a file as a resource. |
T GDFile.Load() | Allows you to load a file as a resource in a generic way. |
File reading method.
Returns the text contained in the file.
public static void MainTest() {
using (GDDirectory dir = GDDirectory.GetGDDirectory()) {
//Here you can enter the file name with or without the extension.
//filetest or filetest.txt
GDFile file = dir.GetFile("filetest");
if (file != null)
GD.Print(file.Read());
}
}
File writing method.
The parameter is text converted into a list of bytes.
public static void MainTest() {
using (GDDirectory dir = GDDirectory.GetGDDirectory()) {
//Here you can enter the file name with or without the extension.
//filetest or filetest.txt
GDFile file = dir.GetFile("filetest");
if (file != null)
file.Write(Encoding.UTF8.GetBytes("A, a zé da manga"));
}
}