Skip to content

ListFiles() Produces an Unwanted Newline Character When Zero Files Are Matched #110

Closed
@relloyd

Description

@relloyd

In the following example pipe, if the glob matches zero files, then a single empty line is supplied to ExecForEach(), which causes the rm command to error:

_, err := script.ListFiles("PY*").ExecForEach("rm -v {{.}}").Stdout()

Can ListFiles() only produce an output if files are matched?

There is a rather ugly workaround that filters blank lines as follows:

_, err := script.ListFiles("PY*").RejectRegexp(regexp.MustCompile("^$")).ExecForEach("rm -v {{.}}").Stdout()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions