🐰 chee cherries quiet party

File Listing with Org Babel

* File Listing Example

This document demonstrates how to list files with bash and use the output in JavaScript.

** List Files with Bash

First, let's get a list of files in the current directory:

#+NAME: files #+BEGIN_SRC bash :results output ls -1 ~/soft/chee/shift/ #+END_SRC

#+RESULTS: files #+begin_example LICENSE README artifacts deno.json deno.lock dist node_modules npm packages tasks #+end_example

** eat it as javascript

let's take that output and convert it to an array

#+BEGIN_SRC js :var fileString=files :results output const files = fileString.trim().split('\n') console.log(files) console.log(files.filter(f => f.startsWith("d")) #+END_SRC

#+RESULTS: : [ : 'LICENSE', 'README', : 'artifacts', 'deno.json', : 'deno.lock', 'dist', : 'node_modules', 'npm', : 'packages', 'tasks' : ] : [ 'deno.json', 'deno.lock', 'dist' ]