2

so im trying to create a simple script to create a directory in dired with a pre defined string (the current date). i have another script that inputs the current date in a format i want

(defun z-insert-date (&optional addTimeStamp-p)

"Insert current date and or time. In this format yyyy-mm-dd.
 When called with `universal-argument', insert date and time, e.g.    2012-05-28T07:06:23-07:00
Replaces text selection.See also `current-date-time-string'."
(interactive "P")
(when (region-active-p) (delete-region (region-beginning) (region- end)   ) )
(cond
((equal addTimeStamp-p nil ) (insert (format-time-string "%d%m%Y")))
(t (insert (current-date-time-string))) ) )

now im struggling how to bring it all togheter. i have this

(defun z/dired-insert-date-folder ()
 ""
 (interactive)
 (dired-create-directory (z-insert-date))
 )

but this dosent work and dosent seem the proper way to do it :)

can anyone point me in the right direction? maybe the z-insert-date function isnt really needed (i want my date to have the format of %d%m%Ythough

2 Answers 2

6

You seem to be over thinking this.

(defun z/dired-insert-date-folder ()
  "Create new directory with current date"
  (interactive)
  (dired-create-directory (format-time-string "%d%m%Y")))

Your reasons are your own of course, but a format of %Y%m%d does tend to sort better.

2
  • That's great. Can we create yymmdd.org in a similar way?
    – Vaibhav
    Commented Jul 20, 2018 at 18:37
  • Use (format-time-string "%Y%m%d.org) for yyyymmdd.org, or "%y%m%d.org" if you actually want yymmdd.org
    – icarus
    Commented Jul 20, 2018 at 18:43
0

Function dired-create-directory expects a string as an argument. Your function z-insert-date that you use as the argument has some minor issues in addition to not returning anything. It only inserts the string in the current buffer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.