OVH Cloud OVH Cloud

Date dans une fonction

4 réponses
Avatar
Jean Magnan de Bornier
Bonjour =E0 tous,
J'ai mis au point une petite fonction qui g=E9n=E8re un fichier .tex, et je
voudrais que la date de cr=E9ation soit rajout=E9e au nom du fichier; mais

(write-file "mocr'%d%m%y'.tex"), ou

(write-file "mocr%d%m%y.tex")

me donnent des fichiers dont le nom est verbatim celui que j'=E9cris dans la
fonction... Je ne trouve pas comment appeler la date en elisp?? Ni "date"
ni "today" ne sont compris. Pourtant ce doit =EAtre facile, alors merci
d'avance...
--=20
Jean=20

4 réponses

Avatar
Bastien
Jean Magnan de Bornier writes:

Bonjour à tous,
J'ai mis au point une petite fonction qui génère un fichier .tex, et je
voudrais que la date de création soit rajoutée au nom du fichier; mais

(write-file "mocr'%d%m%y'.tex"), ou

(write-file "mocr%d%m%y.tex")



(write-file (concat "mocr" (format-time-string "%d%m%Y")))

devrait marcher.

C-h f format-time-string RET :

,----[ format-time-string ]
| format-time-string is a built-in function in `C source code'.
| (format-time-string FORMAT-STRING &optional TIME UNIVERSAL)
|
| Use FORMAT-STRING to format the time TIME, or now if omitted.
| TIME is specified as (HIGH LOW . IGNORED), as returned by
| `current-time' or `file-attributes'. The obsolete form (HIGH . LOW)
| is also still accepted.
| The third, optional, argument UNIVERSAL, if non-nil, means describe TIME
| as Universal Time; nil means describe TIME in the local time zone.
| The value is a copy of FORMAT-STRING, but with certain constructs replaced
| by text that describes the specified date and time in TIME:
`----

--
Bastien
Avatar
Jean Magnan de Bornier
Le 01 mai à 15:57:47 Bastien écrit notamment:

| Jean Magnan de Bornier writes:



| > Bonjour à tous,
| > J'ai mis au point une petite fonction qui génère un fichier .tex, e t je
| > voudrais que la date de création soit rajoutée au nom du fichier; m ais
| >
| > (write-file "mocr'%d%m%y'.tex"), ou
| >
| > (write-file "mocr%d%m%y.tex")



| (write-file (concat "mocr" (format-time-string "%d%m%Y")))



| devrait marcher.

Excellent! Je subodorais que concat devrait intervenir, mais je ne
savais pas trop comment...
Au final, j'ai donc:
(write-file (concat "mocr" (format-time-string "%d%m%Y") ".tex"))

et un grand merci!
à+,
--
Jean
Avatar
Bastien
Jean Magnan de Bornier writes:

(write-file (concat "mocr" (format-time-string "%d%m%Y") ".tex"))



... ah oui, j'avais oublié l'extension!

et un grand merci!



You're welcome.

--
Bastien
Avatar
Matthieu Moy
Jean Magnan de Bornier writes:

Excellent! Je subodorais que concat devrait intervenir, mais je ne
savais pas trop comment...



Ou `format' ...

--
Matthieu