I have a function for generating a new text file. The file is named automatically from date and time, following this format: yyyy-mm-dd--hh-mm-ss.txt
.
However, I also need my function to insert the file name into the first line of the newly made file. The following code is not able to to this, since I am invoking dynamic date and time for both the file name and for the first line in the file. Hence, the text for the file name and for the first line differ by a second or two.
(defun myfun-create-file()
"Doc-string."
(interactive)
(find-file-other-frame (format-time-string "C:/Users/me/notes/%Y-%m-%d--%H-%M-%S.txt") )
(insert (format-time-string "FILE-ID: %Y-%m-%d--%H-%M-%S.txt\n") )
(save-excursion
))
How can I modify my function, by defining the file name first, as a text string variable, and then inserting this string both to the file name an to the first line of the file?