2020-09-26, 19:53
Hier ein kurzes Beispiel, wie man mit Python-Modulen Dateien kopieren, zippen und löschen kann.
import zipfile
from shutil import copyfile
from os import unlink
# copy file
copyfile('dtk-authoryear.bbx' , './dtk-bibliography/dtk-authoryear.bbx')
copyfile('dtk-authoryear.dbx' , './dtk-bibliography/dtk-authoryear.dbx')
copyfile('dtk-bibliography.pdf', './dtk-bibliography/dtk-bibliography.pdf')
copyfile('dtk-bibliography.tex', './dtk-bibliography/dtk-bibliography.tex')
# create the zip file
with zipfile.ZipFile('dtk-bibliography.zip', 'w', zipfile.ZIP_DEFLATED) as z:
z.write('./dtk-bibliography/README.md')
z.write('./dtk-bibliography/dtk-authoryear.bbx')
z.write('./dtk-bibliography/dtk-authoryear.dbx')
z.write('./dtk-bibliography/dtk-bibliography.pdf')
z.write('./dtk-bibliography/dtk-bibliography.tex')
# delete copied files
unlink('./dtk-bibliography/dtk-authoryear.bbx')
unlink('./dtk-bibliography/dtk-authoryear.dbx')
unlink('./dtk-bibliography/dtk-bibliography.pdf')
unlink('./dtk-bibliography/dtk-bibliography.tex') |
import zipfile
from shutil import copyfile
from os import unlink
# copy file
copyfile('dtk-authoryear.bbx' , './dtk-bibliography/dtk-authoryear.bbx')
copyfile('dtk-authoryear.dbx' , './dtk-bibliography/dtk-authoryear.dbx')
copyfile('dtk-bibliography.pdf', './dtk-bibliography/dtk-bibliography.pdf')
copyfile('dtk-bibliography.tex', './dtk-bibliography/dtk-bibliography.tex')
# create the zip file
with zipfile.ZipFile('dtk-bibliography.zip', 'w', zipfile.ZIP_DEFLATED) as z:
z.write('./dtk-bibliography/README.md')
z.write('./dtk-bibliography/dtk-authoryear.bbx')
z.write('./dtk-bibliography/dtk-authoryear.dbx')
z.write('./dtk-bibliography/dtk-bibliography.pdf')
z.write('./dtk-bibliography/dtk-bibliography.tex')
# delete copied files
unlink('./dtk-bibliography/dtk-authoryear.bbx')
unlink('./dtk-bibliography/dtk-authoryear.dbx')
unlink('./dtk-bibliography/dtk-bibliography.pdf')
unlink('./dtk-bibliography/dtk-bibliography.tex')
Uwe Ziegenhagen likes LaTeX and Python, sometimes even combined.
Do you like my content and would like to thank me for it? Consider making a small donation to my local fablab, the Dingfabrik Köln. Details on how to donate can be found here Spenden für die Dingfabrik.
More Posts - Website