The backslash character is special both in string literals (strings typed in Emacs Lisp, surrounded by double quotes) and in regular expressions as well as replacement specifications. Backslash followed by 1–3 octal digits stands for the character with this value, that's why you're seeing
^A (it's the character with the value 1).
Since you want the replacement specification
you need to write it as a string literal as
i.e. surrounded by double quotes, and with a backslash before each backslash or double quote in the replacement specification.
Similarly your regular expression
needs to have a backslash before the backslash character, otherwise the regexp contains
. which matches any character (except a newline). Also you can make the Lisp source more readable by using the
\n syntax instead of a literal newline inside the string. Furthermore your regexp doesn't contain a group; you wanted what's inside the parentheses, so put
.* in a group:
Your function seems to be reinventing
dired-do-query-replace-regexp: open the directory containing the files, mark them (
m to mark one file,
% m to mark files whose name matches a regexp, etc.) and then press
Q and enter the regexp and replacement.