clone url: git://git.m455.casa/ffs
README.md
(Fennel file system utilities)
A collection of file system utilities for Fennel.
The functions in this library were originally written to work with my wg project. Since then, I have tried to improve the functions by putting them into their own library, and fixing them up.
Please use this library with caution. I'm a hobbyist programmer who isn't the best at programming, which means I may have deadly bugs that could result in data loss.
Code blocks and inline code
represents type names, file contents, code blocks, and inline code.ffs.lua
from source)make
ffs.fnl
file.ffs.fnl
file into your project directory.
(local ffs (require :ffs))
This section describes the behaviour of all functions found in ffs, their parameters, and return values.
This section describes shell-related functions.
Takes a shell command and returns the output as a sequence.
(ffs.shell->sequence command) -> sequence
string
sequence
Example: How to print a list of paths in the current directory:
(each [_ v (ffs.shell->sequence "ls")]
(print v))
This section describes path-related functions.
Takes a source path and copies it to the destination path.
Nothing is returned.
(ffs.path-copy source destination) -> No return value
string
string
Example: How to duplicate a file or directory:
(ffs.path-copy "Documents/file.txt" "Documents/copy-of-file.txt")
Takes a path and deletes it without prompting.
Nothing is returned.
(ffs.path-delete path) -> No return value
string
Example: How to delete a file or directory:
(ffs.path-delete "Documents/copy-of-file.txt")
Takes a mode and a sequence of paths and returns a sequence of paths that were not found.
(ffs.paths-missing mode path-sequence) -> sequence
string
[string string ...]
sequence
The mode can be one of the following:
:files
:directories
:paths
Note: Colon-prefixed items evaluate to strings in Fennel, so using
:directories
would be the same as using "directories"
.
Example: How to list missing files based on a list of required files:
(each [_ v (pairs (ffs.paths-missing :files [".bashrc" "something.txt" "test.txt"]))]
(print v))
How to list missing directories based on a list of required directories:
(each [_ v (pairs (ffs.paths-missing :directories [:Documents :Music "Downloads"]))]
(print v))
How to list missing files or directories based on a list of required files or directories:
(each [_ v (pairs (ffs.paths-missing :paths [:Documents ".bashrc" :something]))]
(print v))
This section describes directory-related functions.
Takes a directory and returns true
if it exists, or false
if it
doesn't.
(ffs.directory-exists? directory) -> true or false
string
true
or false
Example: How to print a message if a directory exists or doesn't exist:
(if (ffs.directory-exists? "Documents")
(print "Found 'Documents'!")
(print "Didn't find 'Documents'"))
Takes a directory and creates it, creating the parent directories along with it. If directories exist, they will not be overwritten or recreated.
Nothing is returned
(ffs.directory-create directory) -> No return value
string
Example: How to create a "Projects" directory in your current directory:
(ffs.directory-create "Projects")
Takes a directory and returns the contents of the directory as a sequence.
(ffs.directory-contents directory) -> sequence
string
sequence
Example: How to print a list of contents in a directory:
(each [_ v (pairs (ffs.directory-contents "./"))]
(print v))
This section describes file-related functions.
Takes a file and returns true
if it exists, or false
if it doesn't.
(ffs.file-exists? file) -> true or false
string
true
or false
Example: How to print a message if a file exists or doesn't exist:
(if (ffs.file-exists? ".bashrc")
(print "Found '.bashrc'!")
(print "Didn't find '.bashrc'"))
Takes a file and creates it.
Nothing is returned.
(ffs.file-create file) -> No return value
string
Example: How to create a file:
(ffs.file-create "cool-file.txt")
Takes a file, data to write to the file, and a mode.
Nothing is returned.
(ffs.file-write file data mode) -> No return value
string
string
string
Note: For a list of modes available and their descriptions, see the
io.open
section in the
Lua Reference Manual.
Example: How to write two lines to a file.
(each [_ v (pairs ["first line\n" "second line\n"])]
(ffs.file-write "test.txt" v :a))
Takes a file and returns a loop iterator allowing you to use functions on each line of the file.
(ffs.file->lines file) -> loop iterator
string
Example: How to print all lines from a file:
(each [i (file->lines "file-name.txt")]
(print i))