Skip to content

Append not preprend #7

@ouboub

Description

@ouboub

Hi
First all thanks for the package, I personally prefer the date appended to the name.
The following function does this (emacs 29)


(defun date2name-append-date (path time &optional withtime)
  "Append TIME to PATH as a suffix before the file extension.
If WITHTIME is not nil, use a timestamp according to
`date2name-datetime-format'. Otherwise use `date2name-date-format'."
  (let* ((directory (file-name-directory path))
         ;; Remove any existing date prefix/suffix first
         (filename (date2name-remove-date (file-name-nondirectory path)))
         (base (file-name-sans-extension filename))
         (ext  (file-name-extension filename t)) ;; includes the dot
         (sep  (date2name-choose-separation-character path))
         (datestring (format-time-string
                      (if withtime date2name-datetime-format
                        date2name-date-format)
                      time)))
    ;; Concatenate: directory + base + sep + date + extension
    (concat directory base sep datestring ext)))


(defun date2name-append-date-write (path time &optional withtime)
  "Append TIME to PATH as a suffix and rename the file."
  (let ((new-path (date2name-append-date path time withtime)))
    (unless (string= path new-path)
      (dired-rename-file path new-path nil))))

maybe you find this useful.

Uwe Brauer

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions