1

How can I create a time stamped file name with the org header arg:

#+export_file_name: <timestamp-var> + File name

There is a variable org-time-stamp, is there a way to append it to the static file name to create files with time stamp at time of export in the file name?

Thanks

1
  • There is no such variable AFAIK. There is a function named org-time-stamp but that's a different kettle of fish.
    – NickD
    Mar 11, 2020 at 20:40

2 Answers 2

2

Add this to your init file:

(add-hook 'before-save-hook 'time-stamp)

and this to the Org file:

# Local Variables:
# time-stamp-format: "%04y-%02m-%02d_%f"
# time-stamp-pattern: "^#\\+export_file_name: %%$"
# End:

The value of #+export_file_name: should update every time the file is saved.

3
  • Thanks! Doesn't work for me, not sure why!
    – Gaurav
    Mar 21, 2020 at 3:26
  • 1
    Make sure you (1) add the variables at the end of the file, and (2) kill and reopen the file (or M-x normal-mode) to set them. You also have to add #+export_file_name: nil near the top of the file (and start with some initial value or it won't work).
    – jagrg
    Mar 22, 2020 at 1:57
  • Thanks, that worked. More details on the formatting on the emacs wiki here and the time format in the emacs docs here. %f is the variable for the file name.
    – Gaurav
    Mar 23, 2020 at 4:31
1

It seems like

(org-export-to-file 'pdf (concat "success_" (format-time-string #%FT%H:%M:%S") ".pdf"))

is close to right. The call to concat seems to work, but the call to org-export-to-file doesn't.

Even if I had made this work, I'm not sure how to insert it so that it's run automatically by the exporter.

Help?

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.