I want to run the following .py
script at the command prompt:
connect('weblogic','welcome','t3://localhost:7001')
exportMetadata(application='soa-infra', server='AdminServer',toLocation='C:\soa11g\New\abc_date.zip', docs='/**')
exit()
However, whenever I execute it, I need to create a .zip
file with whose name contains the sysdate, e.g. abc_10082015
or abc_10-08-2015
. How can I do that?
First of all, for your path string, you should prefix r
so that it is treated as raw string, and \
is not treated as escape characters.
Secondly, You can use datetime.datetime.now()
to get the current time , and then use strftime()
to fromat the date as you want. Example -
import datetime
path = r'C:\soa11g\New\abc_%s.zip' % datetime.datetime.now().strftime('%d%m%Y')
connect('weblogic','welcome','t3://localhost:7001')
exportMetadata(application='soa-infra', server='AdminServer',toLocation=path, docs='/**')
exit()
If you want , you can also give format as - '%d_%m_%Y'
to get '10-08-2015'
. You can get such format details from here .