Skip to content

lessp/fs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Note

Exploratory, API subject to change. Suggestions and PRs are always welcome.

Fs

Fs aims to expose a simple filesystem interface for OCaml.

Table of Contents

Installation

opam pin fs https://github.com/lessp/fs.git

Example

For a full list of examples, see the examples/ directory.

File

Create and write to a file

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)

Read a file

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)

Dir

Create a directory

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)

List a directory

match Fs.Dir.list "hello" () with
| Ok files -> List.iter print_endline files
| Error e -> print_endline (Fs.Dir.Error.to_string e)

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published