When I use the createDir
method in Tauri + Typescript, I have to specify a base directory (dir
) in the FsDirOptions
. But I want to give the user himself the possibility to choose a target directory. Can I convert the selected destination path to an fs path constant (such as fs.BaseDirectory.AppLocalData
) with so that I can put the numeric value in the FsDirOptions
?
import {open} from '@tauri-apps/api/dialog';
import {basename} from '@tauri-apps/api/path';
import {createDir} from '@tauri-apps/api/fs';
// 1. the user can choose a destination directory
open({
directory: true,
multiple: false
}).then((directory) => {
// 2. the path to the destination directory is decomposed so that we know the name of the destination directory
basename(directory).then((name) => {
const dir = ...? // only the path to the directory without the basename. I think I have to convert this to u16 for the use in FsDirOptions?
// 3. the directory will be created
createDir(name, {dir, recursive: true}).then(() => {
}).catch((error) => {
console.error(error);
});
}).catch((error) => {
console.error(error);
});
}).catch((error) => {
console.error(error);
});
When I specify the path as a string in the FsDirOptions
under dir
, I get an error message that a string was passed but u16 was expected.
This speaks for the fact that you can only use fs path constants. Probably this is also related to the fact that in tauri.conf.json under tauri.allowlist.fs.scope
exactly these paths have to be enabled? But surely it must be possible for the user to choose where to export to?