Working files and directories in Emacs

Much inspired by @magnars’s excellent s.el and dash.el, f.el is a modern API for working with files and directories in Emacs.


(let* ((dir
        (f-join "~" "tmp" "dir"))
        (f-expand "foo.txt" dir))
        (f-expand "bar.txt" dir)))
  (unless (f-directory? dir)
    (f-mkdir dir))
  (f-write foo-file "SOME ")
  (f-write foo-file "CONTENT" 'append)
  (f-write bar-file "MORE...")
   (lambda (file)
      "File: %s, content: '%s', size: %d"
      (f-relative file dir)
      (f-read file)
      (f-size file)))
   (f-files dir))
  (message "Total size of all files in %s: %d" dir (f-size dir)))

The output will be:

File: bar.txt, content: 'MORE...', size: 7
File: foo.txt, content: 'SOME CONTENT', size: 12
Total size of all files in ~/tmp/dir: 19

blog comments powered by Disqus Back to Top

Fork me on GitHub