Search code examples
permissionsdenoread-access

Is there a way to give read permissions for a subdirectory in Deno?


I have a script that accesses files in a sub-directory. It works when you allow all read access, but all of my attempts at giving read access only to that directory have failed. Is there a way to specify directories via relative paths for --allow-read?


Solution

  • The command

    deno run --allow-read=./resources  .\testread.ts
    

    gives you read access only to the subdirectory ./resources

    so this works:

    const text1 = Deno.readTextFile("./resources/test.txt");
    

    and this throws an exception:

    const text1 = Deno.readTextFile("./test.txt");
    

    PermissionDenied: read access to "./test.txt", run again with the --allow-read flag

    You can also specify more than one directory in a comma separated list:

    deno run --allow-read=./resources,./other  .\testread.ts
    

    If you need write access, it works the same way as for read access:

    deno run --allow-write=./resources,./other  .\testread.ts
    

    Reference: https://deno.land/manual/getting_started/permissions