Note
Exploratory, API subject to change. Suggestions and PRs are always welcome.
Fs
aims to expose a simple filesystem interface for OCaml.
opam pin fs https://github.com/lessp/fs.git
For a full list of examples, see the examples/
directory.
match Fs.File.write "example.txt" ~content:(String "Hello, World!") with
| Ok () -> print_endline "File written!"
| Error e -> print_endline (Fs.File.Error.to_string e)
match Fs.File.append_string "example.txt" ~content:"Hello, World!" with
| Ok () -> print_endline "File written!"
| Error e -> print_endline (Fs.File.Error.to_string e)
As a string:
match Fs.File.read_string "hello.txt" with
| Ok content -> print_endline content
| Error e -> print_endline (Fs.File.Error.to_string e)
Using a custom format:
match Fs.File.read "hello.txt" ~format:Bytes with
| Ok content -> print_endline (Bytes.to_string content)
| Error e -> print_endline (Fs.File.Error.to_string e)
match Fs.Dir.create "hello" () with
| Ok () -> print_endline "Directory created!"
| Error e -> print_endline (Fs.Dir.Error.to_string e)
match Fs.Dir.create "hello/nested" ~recursive:true () with
| Ok () -> print_endline "Directories created!"
| Error e -> print_endline (Fs.Dir.Error.to_string e)
match Fs.Dir.list "hello" () with
| Ok files -> List.iter print_endline files
| Error e -> print_endline (Fs.Dir.Error.to_string e)
MIT