首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在配置的作用域上不允许的未指定路径

在配置的作用域上不允许的未指定路径
EN

Stack Overflow用户
提问于 2022-06-27 16:58:19
回答 2查看 342关注 0票数 1

问题

我一直用read dir获得这个错误,createDir工作得很好,这里没有错误。

代码

Filetree.js

代码语言:javascript
运行
复制
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

代码语言:javascript
运行
复制
"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
      }
    }

版本

代码语言:javascript
运行
复制
> 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设置为:

  • “范围”:"$APP/“、"$APP/**”、"$APP/tree/“
  • “范围”:“$桌面/*”、“$桌面/测试/”
  • “范围”:“$桌面/”、“$桌面/**”、“$桌面/test/”

并在Filetree.js代码中替换了桌面。当我使用App的时候

错误

代码语言:javascript
运行
复制
FileTree.js:23 
        Uncaught (in promise) path not allowed on the configured scope: test

控制台错误日志

我解决了上面的问题

新问题

我现在从文件条目中找不到孩子

文件结构是:

  • parent1 :文件夹
    • child1 :文件夹
    • child2 :文件夹

  • parent2 :文件夹

控制台-没有子级的FileEntry

EN

回答 2

Stack Overflow用户

发布于 2022-08-03 14:40:27

我不知道解决方案是什么,但有一个想法可能是使readDir()函数不像await readDir('test', new Uint8Array([]), { dir: BaseDirectory.Desktop });那样递归,或者如果您知道文件夹的名称,那么分别阅读它们。如果应用程序只使用一种类型的文件/文件扩展名,那么您可以遍历文件条目并检查文件名是否以该扩展名结尾(请确保包含“”。(如".exe"),如果没有,则读取目录。

票数 0
EN

Stack Overflow用户

发布于 2022-11-05 21:27:33

https://tauri.app/v1/api/js/fs/#fs.BaseDirectory.Home“建议只允许列出用于优化包大小和安全性的API。

Tauri.conf.json

代码语言:javascript
运行
复制
  "fs": {
    "all":true,
    "scope": ["**"]
  }

src/main

代码语言:javascript
运行
复制
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://github.com/tauri-apps/tauri/issues/4130

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72775787

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档