pub struct File;Expand description
Access to the file system of the Playdate device.
Implementations§
Source§impl File
impl File
Sourcepub fn list_files(
&self,
path: &str,
) -> Result<impl Iterator<Item = String>, FilePathError>
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.
Sourcepub fn stat(&self, path: &str) -> Result<FilePathStat, FilePathError>
pub fn stat(&self, path: &str) -> Result<FilePathStat, FilePathError>
Reads information about the filemod or folder at path.
pub fn make_folder(&self, path: &str) -> Result<(), FilePathError>
Sourcepub fn rename(&self, from: &str, to: &str) -> Result<(), RenameFilePathError>
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.
Sourcepub fn read_file(&self, path: &str) -> Result<Vec<u8>, FilePathError>
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.
Sourcepub fn write_file(
&self,
path: &str,
contents: &[u8],
) -> Result<(), FilePathError>
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.
Sourcepub fn delete(&self, path: &str) -> Result<(), FilePathError>
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/
Sourcepub fn delete_recursive(&self, path: &str) -> Result<(), FilePathError>
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/