rejeep / f.el

Modern API for working with files and directories in Emacs
GNU General Public License v3.0
680 stars 68 forks source link

Recursive mkdir #110

Closed ChauhanT closed 2 years ago

ChauhanT commented 2 years ago

I was looking for a way to implement recursive mkdir (i.e., mkdir -p). Since the library does not have such a function out of the box, I would like to take a stab at it.

I have called it f-mkdir-recursive. It uses f-traverse-upwards and tries to maintain an interface as similar to f-mkdir as possible. All suggestions about how to make the function more efficient are super welcome.

Initial benchmarking (folder ~/exp was already created before running these tests) shows it is faster than make-directory. I am sure this comes at a cost, but I am not able to tell what this cost is.

#+BEGIN_SRC emacs-lisp
(let ((path "~/exp/make-directory/sub"))
  (benchmark-run 10000
    (make-directory path t)))
#+END_SRC

#+RESULTS:
| 2.011198862 | 1 | 0.29728832399999305 |

#+BEGIN_SRC emacs-lisp
(let ((path "~/exp/f-mkdir-recursive/sub"))
  (benchmark-run 10000
    (f-mkdir-recursive path)))
#+END_SRC

#+RESULTS:
| 1.003087726 | 1 | 0.2717912070000068 |

#+BEGIN_SRC emacs-lisp
(let ((path "~/exp/md"))
  (benchmark-run 10000
    (make-directory path t)))
#+END_SRC

#+RESULTS:
| 1.751611431 | 1 | 0.26697017300000425 |

#+BEGIN_SRC emacs-lisp
(let ((path "~/exp/fmr"))
  (benchmark-run 10000
    (f-mkdir-recursive path)))
#+END_SRC

#+RESULTS:
| 0.6851341670000001 | 0 | 0.0 |
ChauhanT commented 2 years ago

I find it rather confusing and don't agree with it. But you're the maintainer, merge away. The core functionality of f.el remains as solid as ever.