globbing.pai

< Prev | Back | Next >


# This example compares globbing in Paisley vs Bash.

# In bash, you might do something like this:
# for i in some/dir/{a,b,c}.txt; do
#   echo $i
# done

# In Paisley, you can do the same thing with the `glob` function:
for i in {'some/dir/*.txt'.glob('a', 'b', 'c')} do
  print {i}
end
print
# It's a little more verbose, but it uses the same syntax as the rest of the language, rather than anything special.

# If you want to filter globs based on existing files, you can use `file_glob`:
for i in {'examples/*.pai'.file_glob()} do
    print {i}
end
print

# The above would print all files in `examples/` that end with `.pai`.
# It does the same thing as the following bash command:
# for i in examples/*.txt; do
#   echo $i
# done

# Note that file_glob does not work if the @ plasma or @ sandbox annotations
# (or their respective compiler flags) are used, since file_glob interacts with the filesystem.

< Prev | Back | Next >