Replies: 1 comment 1 reply
-
https://doc.rust-lang.org/std/fs/struct.File.html#examples (second one is for reading) + tauri's PathResolver so a minimal example using the setup hook (which runs on app start so potentially useless idk) tauri::Builder::default()
.setup(|app| {
let dir = app.path_resolver().app_data_dir().expect("couldn't resolve app data dir").join("users/");
// you may want to check if the dir and/or files exist first
// also the unwraps should be replaced with proper error handling
// if you want to get the file as binary, just remove the from_utf8_lossy call.
let contents = String::from_utf8_lossy(&std::fs::read("address.txt").unwrap()).parse().unwrap();
Ok(())
}) If you need this somewhere where you don't have access to an AppHandle or Window, you could tauri::path::data_dir() and add your bundle identifier as a folder to that (this is what appdatadir is)
The "most intended" way is to use tauri events https://tauri.app/v1/guides/features/events/ |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm new to rust and tauri. I currently write some data to a file using the file api (in javascript). Now I need to read the file data in my main.rs. What is the best approach to access the filesystem from my rust code?
Is there a way to call my javascript/the javascript file-api from the main.js or is there a rust-api where I can similiary access the filesystem folders?
Example:
In javascript I write to $APPDATA/users directory using the constants BaseDirectory.AppData:
https://tauri.app/v1/api/js/fs/#createdir
How could I read this folder from main.js? And is there some way to call my javascript code from main,js?
Thanks in advance &
Best regards,
Manuel
Beta Was this translation helpful? Give feedback.
All reactions