I have a folder full of .tex files and I would like to write these file names to file, each inside an identical wrapper.
For example, let’s say that I have a folder with three .tex files A.tex, B.tex, and C.tex, although the file names don’t follow a simple pattern. These .tex files are tables and I would like to wrap them to get \begin{table} \input{A.tex} \end{table} and so on.
My first thought was that there could be a LaTeX solution, but looking around at TeX SE it seems that this may be better handled in a Vim (specifically the third answer here). Or is this a task better handled by Perl or some other scripting language? (I have limited Perl knowledge, but this would motivate me to learn more). Thanks!
In case of filenames that do not contain newline characters, the issue can be
easily solved in Vim script:
or
The commands above uses the
glob()function to collect the list of filenamesmatching given wildcard. Resulting set of filenames is represented as
a string containing paths separated with newline characters. Using the
split()function, the string is broken down into list, which is processed bythe
map()function to format filenames according to desired text template.Then, strings from this list are inserted below the current line with the
append()function.Another way of populating a list of filenames in a buffer is to insert output
of system directory-listing command through the
:read!command,In order to format the list as necessary, run
immediately after executing the previous command.