First commit

This commit is contained in:
2025-05-09 12:48:33 -05:00
commit 53bbd61642
11 changed files with 697 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
+++
title = 'Working with files'
date = 2025-05-08T22:23:44-05:00
+++
## Write text to file
```go
FS.WriteAllText(FS.Local, "file.txt", "Some text");
```
## Read text from file
```go
var text = FS.ReadAllText(FS.Local, "file.txt");
```
## Create a directory
```go
FS.Local.CreateDirectory("New Folder");
FS.Local.CreateDirectory("Folder" / "Another Folder"); // we can create folders even if parents don't exist
```
## Enumerating entries in folder
```go
each(var file : FS.Local.EnumeratePaths(/))
{
if(FS.Local.DirectoryExists(file)) Console.Write("DIR ");
Console.WriteLine(file);
}
```
### Exists
```go
FS.Local.FileExists("/path/to/file"); //use FS.Local.RegularFileExists("/path/to/file"); if you don't want special files to be considered
FS.Local.DirectoryExists("/path/to/directory");
```
### Opening files
See [Streams](streams.md) for more details on the Stream object
```go
var strm = FS.Local.OpenFile("/path/to/file.bin", "rb");
//use strm.Read(buffer,buffer_offset,length); to read some data, returns number of bytes read
strm.Close();
```