Skip to content

How do you iterate all files with a specified suffix under a folder? #151

Closed Answered by Ph0enixKM
flyisland asked this question in Q&A
Discussion options

You must be logged in to vote

@flyisland @firatkucuk You can use the experimental standard library function to get lines out of the output. The standard library will be documented soon once we make sure it's stable enough. It should be ready in under a month.

Here is a minimal example:

import { lines } from "std"

loop index, file in lines(unsafe $ls -a$) {
    echo "{index}: {file}"
}

Here is the updated version of this code:

import { lines } from "std"

let base_dir="/tmp"

let zip_files = $ls {base_dir}/*.zip$ failed {
    echo "It seems that the '{base_dir}' does not exist"
}
loop file in lines(zip_files) {
    echo "Extracting {file}"
}

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@flyisland
Comment options

Answer selected by Ph0enixKM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants