Filesystem

Core ships with a filesystem abstraction that makes it easy to switch from a local filesystem to a remote one. The default driver that is shipped provides access to the local filesystem but using your own filesystem driver is just as easy.

Filesystem Usage

Determine if a file exists

1app
2 .get<Services.Filesystem.FilesystemService>(Container.Identifiers.FilesystemService)
3 .exists("/home/ark/stats.txt");

Get the contents of a file

1app
2 .get<Services.Filesystem.FilesystemService>(Container.Identifiers.FilesystemService)
3 .get("/home/ark/stats.txt");

Write the contents of a file

1app
2 .get<Services.Filesystem.FilesystemService>(Container.Identifiers.FilesystemService)
3 .put("/home/ark/stats.txt", "Hello World");

Delete the file at a given path

1app
2 .get<Services.Filesystem.FilesystemService>(Container.Identifiers.FilesystemService)
3 .delete("/home/ark/stats.txt");

Copy a file to a new location

1app
2 .get<Services.Filesystem.FilesystemService>(Container.Identifiers.FilesystemService)
3 .copy("/home/ark/old.txt", "/home/ark/new.txt");

Move a file to a new location

1app
2 .get<Services.Filesystem.FilesystemService>(Container.Identifiers.FilesystemService)
3 .move("/home/ark/old.txt", "/home/ark/new.txt");

Get the file size of a given file

1app
2 .get<Services.Filesystem.FilesystemService>(Container.Identifiers.FilesystemService)
3 .size("/home/ark/stats.txt");

Get the file’s last modification time

1app
2 .get<Services.Filesystem.FilesystemService>(Container.Identifiers.FilesystemService)
3 .lastModified("/home/ark/stats.txt");

Get an array of all files in a directory

1app
2 .get<Services.Filesystem.FilesystemService>(Container.Identifiers.FilesystemService)
3 .files("/home/ark");

Get all of the directories within a given directory

1app
2 .get<Services.Filesystem.FilesystemService>(Container.Identifiers.FilesystemService)
3 .directories("/home/ark");

Create a directory

1app
2 .get<Services.Filesystem.FilesystemService>(Container.Identifiers.FilesystemService)
3 .makeDirectory("/home/ark");

Recursively delete a directory

1app
2 .get<Services.Filesystem.FilesystemService>(Container.Identifiers.FilesystemService)
3 .deleteDirectory("/home/ark");
Last updated 8 months ago
Edit Page
Share: