Jump to content

How to pass date in save as file name using autoit?


Recommended Posts

I am using autoIt to handle the saveAs dialog box in selenium java. Here, I should save the pdf file in required directory
ControlFocus("Save As","","Edit1")
ControlSend("Save As","","Edit1","-----My file path\file_name.pdf")
ControlClick("Save As","","Button2")

Is it possible to add today's date or last weekend date(Saturday) in my file name and send in the file path to get saved?

Link to post
Share on other sites
23 minutes ago, emiley said:

Is it possible to add today's date ... in my file name and send in the file path to get saved?

[NOT TESTED]

Local $sFilepath = "-----My file path\file_name" & "-" & @YEAR & "-" & @Mon & "-" & @MDAY & ".pdf"
ControlFocus("Save As","","Edit1")
ControlSend("Save As","","Edit1",$sFilepath)
ControlClick("Save As","","Button2")

 

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to post
Share on other sites
30 minutes ago, Musashi said:

[NOT TESTED]

Local $sFilepath = "-----My file path\file_name" & "-" & @YEAR & "-" & @Mon & "-" & @MDAY & ".pdf"
ControlFocus("Save As","","Edit1")
ControlSend("Save As","","Edit1",$sFilepath)
ControlClick("Save As","","Button2")

 

Thanks, it added today's date in my file name! But, I am still trying to figure out how to add last weekend (saturday) date here.

Link to post
Share on other sites
2 hours ago, emiley said:

Thanks, it added today's date in my file name! But, I am still trying to figure out how to add last weekend (saturday) date here.

Try this :

#include <Date.au3>

Local $sFilepath, $sCurrentDate, $aYMD, $iWeekday, $sDateLastSaturday
$sCurrentDate = _NowCalcDate()
$aYMD = StringSplit($sCurrentDate, "/", 2)
$iWeekday  =  _DateToDayOfWeek($aYMD[0], $aYMD[1], $aYMD[2])
$sDateLastSaturday = _DateAdd("D", - $iWeekday, $sCurrentDate)
$sFilepath = "-----My file path\file_name" & "-" & StringReplace($sDateLastSaturday, "/", "-") & ".pdf"
ControlFocus("Save As","","Edit1")
ControlSend("Save As","","Edit1",$sFilepath)
ControlClick("Save As","","Button2")

 

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...