Skip to content

allow dir_ls to recursively list linked directories #518

Description

@bhogan-mitre

GIven this test, it looks like dir_ls intentionally does not follow symbolic links.

it("Does not follow symbolic links", {

I think it would be useful to list the contents of symbolically-linked directories. Would you consider an option to support this? For example, I'd like to see that the linked directory contains files A and B in the reprex below.

library(fs)

# modfied from example script at https://fs.r-lib.org/reference/copy.html

# make dir foo with multiple files
foo_dir <- dir_create(tempdir(), "foo")

file_create(foo_dir, c("A", "B"))

dir_ls(foo_dir)
#> /var/folders/wg/tq2qzp8s4yq1vhh2x_ldwc0c0000gn/T/Rtmp1Po6JD/foo/A
#> /var/folders/wg/tq2qzp8s4yq1vhh2x_ldwc0c0000gn/T/Rtmp1Po6JD/foo/B

# make dir bar with symbolic link to dir foo
bar_dir <- dir_create(tempdir(), "bar")
link_create(
  path = foo_dir,
  new_path = path(bar_dir, "loo")
)

# list bar contents
dir_ls(bar_dir, recurse = TRUE)
#> /var/folders/wg/tq2qzp8s4yq1vhh2x_ldwc0c0000gn/T/Rtmp1Po6JD/bar/loo

Created on 2026-06-12 with reprex v2.1.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions