Skip to content

Commit

Permalink
add filesystem cookbook
Browse files Browse the repository at this point in the history
  • Loading branch information
loyer78 authored and sabine committed May 9, 2024
1 parent ffbc218 commit 445d24a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
26 changes: 26 additions & 0 deletions data/cookbook/file-system/00-stdlib.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
packages: []
discussion: |
- **Reference:** All the presented functions are available in the [Sys module reference](https://v2.ocaml.org/api/Stdlib.Sys.html)
---
(* Testing the presence of a file/directory *)
let () = if Sys.file_exists "my_file" then
print_string "The file/directory exists."
(* Testing if file or directory which exists is a directory. *)
let () = if Sys.is_directory "my_file" then
print_string "It is a directory."
else
print_string "It is a file (regular or not)."
(* Deleting a file *)
let () = Sys.remove "my_file"
(* Renaming a file *)
let () = Sys.rename "my_file" "new_name"
(* Changing the current directory *)
let () = Sys.chdir "new_directory_path"
(* Deleting a directory *)
let () = Sys.rmdir "directory_name"
(* Listing a directory *)
let () =
let file_array = Sys.readdir "directory_name" in
Array.iter (fun filename -> Printf.printf "%s\n" filename) file_array

4 changes: 4 additions & 0 deletions data/cookbook/tasks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ categories:
description: >
Use ANSI escape codes for cursor location, font and colour in video text
terminal emulators.
- title: File System
tasks:
- title: Miscellaneous File System Operations
slug: file-system
- title: Compilation & Linking
tasks:
- title: Compile and Link to a Bundled C Library
Expand Down

0 comments on commit 445d24a

Please sign in to comment.