Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function to list all files in a directory #18

Closed
vituri opened this issue Sep 2, 2024 · 5 comments
Closed

Function to list all files in a directory #18

vituri opened this issue Sep 2, 2024 · 5 comments

Comments

@vituri
Copy link

vituri commented Sep 2, 2024

Not really an issue!

I often find myself redefining something like this:

function list_files(path="", pattern="")
    files =
        @chain begin
            map(walkdir(path)) do (root, dirs, files)
                joinpath.(root, files)
            end
            reduce(vcat, _)
            filter(x -> occursin(pattern, x), _)
        end

    files
end;

inspired by the list.files from base R. Many times I just want to list all the files in folders and subfolders, which optionally satisfy some string pattern. Is TidierFiles the place to define and export it? What do you think?

@drizk1
Copy link
Member

drizk1 commented Sep 2, 2024

I think this is pretty neat and definitely see the utility

Just out of curiosity, it possible to write the function with the using @chain to avoid adding a new dependency ?

@drizk1
Copy link
Member

drizk1 commented Sep 4, 2024

here is a @chain free version, @vituri . off some prelim testing it seems to yield the same results.

function list_files(path = "", pattern = "")
    files = map(walkdir(path)) do (root, dirs, files)
        joinpath.(root, files)
    end
    files = reduce(vcat, files)
    files = filter(x -> occursin(pattern, x), files)
    return files
end

i think this definitely fits in to tidierfiles. Would u like to throw in a PR for it? I can if not

@vituri
Copy link
Author

vituri commented Sep 4, 2024

Thanks, @drizk1 ! The function looks fine. I think you can do the PR, because you probably know the best place to put this function.

After the merge, I will download the github version of the package and never again will need to redefine this thing!! A dream coming true!

@drizk1
Copy link
Member

drizk1 commented Sep 4, 2024

alright go head and give the new branch a shot.

if it works as u need it to, ill go ahead and merge and release

using Pkg; Pkg.add(url = "https://github.com/TidierOrg/TidierFiles.jl", rev = "add-list_files")

@drizk1 drizk1 mentioned this issue Sep 4, 2024
@vituri
Copy link
Author

vituri commented Sep 9, 2024

image

Looks good! Thanks, @drizk1 !

@vituri vituri closed this as completed Sep 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants