问题
我一直用read dir获得这个错误,createDir工作得很好,这里没有错误。
代码
Filetree.js
import { readDir,createDir, BaseDirectory } from '@tauri-apps/api/fs';
import { appDir } from '@tauri-apps/api/path';
let defineEntries = async () => {
console.log("Loading Data");
entries = await readDir('test', new Uint8Array([]), { dir: BaseDirectory.Desktop, recursive: true });
console.log("Success");
}
Tauri.conf.json
"tauri": {
"allowlist": {
"fs": {
"all": true,
"readFile": true,
"writeFile": true,
"readDir": true,
"copyFile": true,
"createDir": true,
"removeDir": true,
"removeFile": true,
"renameFile": true,
"scope": ["$DESKTOP/*", "$DESKTOP/**", "$DESKTOP/test/*"]
},
"path": {
"all": true
}
}
版本
> tauriplayground@0.1.0 tauri
> tauri "info"
Environment
› OS: Windows 10.0.19044 X64
› Webview2: 103.0.1264.37
› MSVC:
- Visual Studio Build Tools 2019
› Node.js: 16.14.2
› npm: 8.5.0
› pnpm: Not installed!
› yarn: 1.22.19
› rustup: 1.24.3
› rustc: 1.61.0
› cargo: 1.61.0
› Rust toolchain: stable-x86_64-pc-windows-msvc
Packages
› @tauri-apps/cli [NPM]: 1.0.0
› @tauri-apps/api [NPM]: 1.0.1
› tauri [RUST]: 1.0.0,
› tauri-build [RUST]: 1.0.0,
› tao [RUST]: 0.11.2,
› wry [RUST]: 0.18.3,
App
› build-type: bundle
› CSP: unset
› distDir: ../build
› devPath: http://localhost:3000/
› framework: React
App directory structure
├─ node_modules
├─ public
├─ src
├─ src-tauri
└─ tree
我试过的
我将tauri.conf.json设置为:
并在Filetree.js代码中替换了桌面。当我使用App的时候
错误
FileTree.js:23
Uncaught (in promise) path not allowed on the configured scope: test
我解决了上面的问题
新问题
我现在从文件条目中找不到孩子
文件结构是:
树
发布于 2022-08-03 14:40:27
我不知道解决方案是什么,但有一个想法可能是使readDir()
函数不像await readDir('test', new Uint8Array([]), { dir: BaseDirectory.Desktop });
那样递归,或者如果您知道文件夹的名称,那么分别阅读它们。如果应用程序只使用一种类型的文件/文件扩展名,那么您可以遍历文件条目并检查文件名是否以该扩展名结尾(请确保包含“”。(如".exe"),如果没有,则读取目录。
发布于 2022-11-05 21:27:33
https://tauri.app/v1/api/js/fs/#fs.BaseDirectory.Home“建议只允许列出用于优化包大小和安全性的API。
Tauri.conf.json
"fs": {
"all":true,
"scope": ["**"]
}
src/main
import { readDir, BaseDirectory } from "@tauri-apps/api/fs";
// Reads the `Desktop` directory recursively
const entries = await readDir("", {
dir: BaseDirectory.Desktop,
recursive: true,
});
function processEntries(entries) {
for (const entry of entries) {
console.log(`Entry: ${entry.path}`);
if (entry.children) {
processEntries(entry.children);
}
}
}
processEntries(entries);
https://stackoverflow.com/questions/72775787
复制相似问题