You have to open the files to add text to them.
Can you know which files you want to add this text to, i.e., which files do not already have such text?
If so, you can use make-header
, from header2.el
, to add that text as a (temporary) file header. (See also Automatic File Headers.)
If not, then you can do the same thing, but conditionally: check for such text first, to prevent inserting it again.
When you first visit a file in Emacs, point (cursor position) is automatically at the start of the file. And anyway, make-header
always inserts the header at the buffer beginning, regardless of whether the file is already visited in a buffer and the point might not be at the buffer beginning when it is called.