File

Struct File 

Source
pub struct File;
Expand description

Access to the file system of the Playdate device.

Implementations§

Source§

impl File

Source

pub fn list_files( &self, path: &str, ) -> Result<impl Iterator<Item = String>, FilePathError>

Returns an iterator with every file or subfolder found at path.

Subfolders are indicated by a slash ‘/’ suffix in the filename. list_files() does not recurse into subfolders.

Source

pub fn stat(&self, path: &str) -> Result<FilePathStat, FilePathError>

Reads information about the filemod or folder at path.

Source

pub fn make_folder(&self, path: &str) -> Result<(), FilePathError>

Source

pub fn rename(&self, from: &str, to: &str) -> Result<(), RenameFilePathError>

Renames the file or folder at from to to.

This function will overwrite the file at to without confirmation, but will fail to rename a folder when another exists with the same name. It does not create intermediate folders.

Source

pub fn read_file(&self, path: &str) -> Result<Vec<u8>, FilePathError>

Read the entire contents of the file at path.

The function will try to read from the game’s data folder, and if it cannot find the file there, it will fallback to look in the game pdx.

Source

pub fn write_file( &self, path: &str, contents: &[u8], ) -> Result<(), FilePathError>

Write contents into the file at path in the game’s data folder.

If a file exists at path it will be overwritten, otherwise a file will be created. If a folder exists at path, the write will fail.

Source

pub fn delete(&self, path: &str) -> Result<(), FilePathError>

Deletes the file or folder at path in the game’s data folder.

BUG: This is currently broken, and always reports “permission denied” in the simulator: https://devforum.play.date/t/unlink-gives-permission-denied-in-c-api-in-windows-simulator/4979

If the path is to a non-empty folder, it will fail. The path will be relocated relative to the Data/ folder, so it can not refer to things that are part of the game’s pdx image.

Source

pub fn delete_recursive(&self, path: &str) -> Result<(), FilePathError>

Deletes the file at path, or the folder and its contents. The path is searched for in the game’s data folder.

BUG: This is currently broken, and always reports “permission denied” in the simulator: https://devforum.play.date/t/unlink-gives-permission-denied-in-c-api-in-windows-simulator/4979

If the path is a folder, and all files and folders inside it are deleted as well. The path will be relocated relative to the Data/ folder, so it can not refer to things that are part of the game’s pdx image.

Trait Implementations§

Source§

impl Debug for File

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for File

§

impl RefUnwindSafe for File

§

impl Send for File

§

impl Sync for File

§

impl Unpin for File

§

impl UnwindSafe for File

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.