On Dec 28, 9:32 ¨Âí¬ ÁÍ ¼áì®®®Àðïííå®ãïí÷òïôåº > Hello > > object : > +++++ > > ¨Â îåöåíáäå óãòéðô ÷éôè Òõâù ¨áîä ÷éôè ðùôèïî ¡©> I would like to translate a little script from python to ruby to insert it > ¨Âîóéäâõîäìå íáäå ÷éôè òõâù áî÷ïõììéëå ÷éôè ôèéó ôòôï ÷ïòë > ¨Â ìéôôìå ÷éôè òõâù÷ïòë ÷éôè ÏÓ áîèáöå òõâù ±®¸®·® > > the script in python : > ++++++++++++++++++ > > ------------------------------------------------------------------------------- > #!/usr/bin/env > > python -u > # -*- coding: utf-8 -*- > > import glob > > HEADER = r"""\input{Vorspann.ltx} > > \begin{document} > > %s > \end{document} > """ > > texFiles = glob.glob('*.tex') > > for fname in texFiles[:]: > #print fname > > text = file(fname, 'rb').read() > > text2 = HEADER % text > > fh = file('new/%s' % fname, 'wb') > fh.write(text2) > fh.close() > ------------------------------------------------------------------------------- > > Explanation > > : > +++++++++ > > The script is in a folder F with text (here it's tex) files (utf8 files) > The script reads the aTeX iles inside F then > t adds the line : \input{preamble.ltx} > > and to finish it puts around the initial lines two lines: > > \begin{document} > > \end{document} > > Example : > +++++++ > > test.tex is a text file which contains : > > I'm a file test. > > the result is a file with the same name in a subfolder named "new" > and text.tex now contains :: > > \input{preamble.ltx} > \begin{document} > I'm a file test. > \end{document} > > I hope someone can help me > > Thanks and best regards > > AM > > PS : What is the better book to learn how to script with ruby ? require 'ftools' HEADER = '\input{Vorspann.ltx} \begin{document} %s \end{document} ' File.makedirs( "new" ) Dir[ "*.tex" ].each{|fname| text = IO.read( fname ) text2 = HEADER % text File.open( "new/" + fname, "wb" ){|fh| fh.print text2 } }