Diana (Cda) Posted February 8, 2022 Share Posted February 8, 2022 Hello everyone! I have a script I don't know how to fix. It's for creating a "reporting" folder which hold documents that are saved to it that gets created every 2 weeks. The input start date is fine but I've always done the 2nd date manually, while I know there'd be an easy way to AutoIt to enter the 2nd date automatically. Here's an example of the end result: 2022.01.23.Sn-02.05.Sa- #14 The first date (2022.01.23.Sn) is the one input. The 2nd date in MMM.DD.DDD format (02.05.Sa) is what AutoIt can hopefully calculate and input automatically, the 2nd Saturday from the first date input. Here is my existing code: expandcollapse popup; #Include <Date.au3> #include<_My_DATE.au3> ; my date, time conventions, etc. #NoTrayIcon ; AutoIt's icon doesn't show in systray TraySetIcon("Shell32.dll", 147) ; changes the icon displayed in the systray AutoItSetOption("WinTitleMatchMode", 2) ; this allows partial window titles to be valid! ;------------------------------------------------------------------------------------------------------------------------- #RequireAdmin #Region --- CodeWizard generated code Start --- ;InputBox features: Title=Yes, Prompt=Yes, Default Text=Yes, Width=250, Height=125 If Not IsDeclared("sInputBoxAnswer") Then Local $sInputBoxAnswer ;===================================================================================================== $BoxTitle = "Reporting Period" $LineTitle = "yyyy.mm.dd.ddd" & @CRLF & "(The _FIRST_SUNDAY_ of the reporting period ...)" $BoxWidth = "525" $BoxHeight = "145" ;===================================================================================================== $sInputBoxAnswer = InputBox($BoxTitle, $LineTitle & @CRLF & @CRLF, $YrDate_Long," ", $BoxWidth, $BoxHeight, Default, Default) ; width, heigh, left ("Default" centers box), top ("Default" centers box). Select Case @Error = 0 ;OK - The string returned is valid ClipPut($sInputBoxAnswer) Case @Error = 1 ;The Cancel button was pushed Exit ; finished Case @Error = 3 ;The InputBox failed to open Exit ; finished EndSelect #EndRegion --- CodeWizard generated code End --- #Region --- CodeWizard generated code Start --- ;InputBox features: Title=Yes, Prompt=Yes, Default Text=Yes, Width=250, Height=125 If Not IsDeclared("sInputBoxAnswer") Then Local $sInputBoxAnswer $sInputBoxAnswer = InputBox("Reporting Period?","What reporting period are you covering in this folder, i.e., ''1'', ''2'', or ''3'', ''1'' being the number corresponding to the very first report you input for ...","(1, 2, or 3, etc.)"," ","250","150", Default, Default) ; width, height, left ("Default" centers box), top ("Default" centers box). Select Case @Error = 0 ;OK - The string returned is valid ;============================================================================== $PathAndFldrName = @ScriptDir & "\" & ClipGet() & "-" & @MON & "." & @MDAY & "." & $ShortDayMyFormat & "- #" & $sInputBoxAnswer ;============================================================================== DirCreate($PathAndFldrName) Sleep(50) ; Taking out syntax that creates subfolders, not needed here. Case @Error = 1 ;The Cancel button was pushed Exit ; finished Case @Error = 3 ;The InputBox failed to open Exit ; finished EndSelect #EndRegion --- CodeWizard generated code End --- Thank you! Any help appreciated. Cheers. Link to comment Share on other sites More sharing options...
Subz Posted February 8, 2022 Share Posted February 8, 2022 Didn't really follow the entire script, but you can use something like: expandcollapse popup#include <Date.au3> $sDate = "2022/01/23" MsgBox(4096, "", _GetDate($sDate)) Func _GetDate($_sDate, $_iDayCount = 14) Local $aSrcDate = StringSplit($_sDate, "/", 2) Local $sSrcDate = StringReplace($_sDate, "/", ".") Local $sSrcDay = _GetDayofWeek(_DateToDayOfWeek($aSrcDate[0], $aSrcDate[1], $aSrcDate[2])) Local $sTgtDate = _DateAdd("D", $_iDayCount - 1, $_sDate) Local $aTgtDate = StringSplit($sTgtDate, "/", 2) $sTgtDate = StringReplace($sTgtDate, "/", ".") Local $sTgtDay = _GetDayofWeek(_DateToDayOfWeek($aTgtDate[0],$aTgtDate[1],$aTgtDate[2])) Local $sResult = $sSrcDate & "." & $sSrcDay & "-" & $aTgtDate[1] & "." & $aTgtDate[2] & "." & $sTgtDay & "- #" & $_iDayCount Return $sResult EndFunc Func _GetDayofWeek($_iDayofWeek) Local $sDay Switch $_iDayofWeek Case 1 $sDay = "Sn" Case 2 $sDay = "Mn" Case 3 $sDay = "Tu" Case 4 $sDay = "Wd" Case 5 $sDay = "Th" Case 6 $sDay = "Fr" Case 7 $sDay = "Sa" EndSwitch Return $sDay EndFunc Link to comment Share on other sites More sharing options...
Diana (Cda) Posted February 8, 2022 Author Share Posted February 8, 2022 (edited) Thank you! Oh, dear, you lost me. I'm a very basic AutoIt user even after all these years and I only know how to work with existing code and don't know how to work with something that is completely different esp. as this produces a popup and not anything with userinput and creating a folder (sorry!!). How about this, I'm thinking that if there was an easy way to just add the date in this line: $PathAndFldrName = @ScriptDir & "\" & ClipGet() & "-" & @MON & "." & @MDAY & "." & $ShortDayMyFormat & "- #" & $sInputBoxAnswer specifically, where @MON & "." & @MDAY gets the 2nd Saturday dumped in calculated from the first date as per user input that then gets dumped in via the ClipGet()?? Is that easier, perhaps? Thx! Edited February 8, 2022 by Diana (Cda) Link to comment Share on other sites More sharing options...
junkew Posted February 11, 2022 Share Posted February 11, 2022 (edited) Save this as createFolder.ps1 and it will do all the work for you from powershell in a few lines $today=get-date # Todays date $date1=$today.AddDays(-$today.Dayofweek.value__+1).date #Calculate the date of the monday in the week you run this $date2=$date1.AddDays(+13).date #Just add 13 days $newFolderName=$psscriptroot + '\' + $date1.tostring('yyyy.MM.dd.ddd') + '-' + $date2.tostring('yyyy.MM.dd.ddd') #Format it new-item $newFolderName -itemtype directory -ErrorAction Ignore If you want from AutoIt then you do not need that clipget() and clipput() just refer to sInputBoxAnswer Edited February 11, 2022 by junkew FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
ad777 Posted February 11, 2022 Share Posted February 11, 2022 (edited) @Diana (Cda) you mean like this.. The first date (2022.01.23.Sn) is the one input. The 2nd date in MMM.DD.DDD format (02.05.Sa) $PathAndFldrName = @YEAR & "." & @MON + 4 & "." & @MDAY + 6 DirCreate($PathAndFldrName) or Maybe this: expandcollapse popup; #include <Date.au3> ;#include<_My_DATE.au3> ; my date, time conventions, etc. #NoTrayIcon ; AutoIt's icon doesn't show in systray TraySetIcon("Shell32.dll", 147) ; changes the icon displayed in the systray AutoItSetOption("WinTitleMatchMode", 2) ; this allows partial window titles to be valid! ;------------------------------------------------------------------------------------------------------------------------- #RequireAdmin #Region --- CodeWizard generated code Start --- ;InputBox features: Title=Yes, Prompt=Yes, Default Text=Yes, Width=250, Height=125 If Not IsDeclared("sInputBoxAnswer") Then Local $sInputBoxAnswer ;===================================================================================================== $BoxTitle = "Reporting Period" $LineTitle = "yyyy.mm.dd.ddd" & @CRLF & "(The _FIRST_SUNDAY_ of the reporting period ...)" $BoxWidth = "525" $BoxHeight = "145" ;===================================================================================================== $sInputBoxAnswer = InputBox($BoxTitle, $LineTitle & @CRLF & @CRLF, "2021.01.20.Sa", " ", $BoxWidth, $BoxHeight, Default, Default) ; width, heigh, left ("Default" centers box), top ("Default" centers box). Select Case @error = 0 ;OK - The string returned is valid ClipPut($sInputBoxAnswer) Case @error = 1 ;The Cancel button was pushed Exit ; finished Case @error = 3 ;The InputBox failed to open Exit ; finished EndSelect #EndRegion --- CodeWizard generated code Start --- Global $YMD = $sInputBoxAnswer ;;"2022.01.20.Sa" $NEXTMonth = 1 ;mean +1 the next month +1 $NEXTDay = -15 ; mean -15 the prev day -15 MsgBox(0, "", PDate($YMD, $NEXTMonth, $NEXTDay)) ;RESULT = (02.05.Sa) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;################PDATE#################### Func PDate($YMD, $INCM, $INCD) $QEE = StringMid($YMD, 9, 2) If Number($QEE) < Number("9") Then $state3 = "on" EndIf Global $inc, $add, $SData, $state = "on", $state2 = "on", $state3 For $i = 1 To StringLen($YMD) If StringMid($YMD, $i, 1) = "." Then $inc = $inc + 1 Else If $inc = 1 Then Else If $inc = 2 Or $inc = 3 Then Else $add &= StringMid($YMD, $i, 1) EndIf EndIf If $inc = 1 Then If StringMid($YMD, $i, 2) > 9 Then $add &= StringMid($YMD, $i, 2) + $INCM ; Else If $state = "on" Then $add &= "." & "0" & StringMid($YMD, $i, 2) + $INCM & "." ; $state = "off" EndIf EndIf EndIf If $inc = 2 Then If StringMid($YMD, $i, 2) < 9 Then If $state3 = "on" Then $SData = StringMid($YMD, $i, 2) $add &= "0" & StringMid($YMD, $i + 1, 2) ; $state3 = "off" EndIf Else If $state2 = "on" Then $SData = StringMid($YMD, $i, 2) $add &= StringMid($YMD, $i, 2) + $INCD & "." ; $state2 = "off" EndIf EndIf ; if $ EndIf If $inc = 3 Then If StringReplace(StringRight($add, 3), ".", "") > 30 Then $add = StringReplace($add, StringReplace(StringRight($add, 3), ".", ""), "1") EndIf If StringReplace(StringRight($add, 3), ".", "") = "1" Or StringReplace(StringRight($add, 3), ".", "") = "12" Or StringReplace(StringRight($add, 3), ".", "") = "15" Or StringReplace(StringRight($add, 3), ".", "") = "22" Or StringReplace(StringRight($add, 3), ".", "") = "29" Then $add &= "Tu" If StringReplace(StringRight($add, 3), ".", "") = "2" Or StringReplace(StringRight($add, 3), ".", "") = "9" Or StringReplace(StringRight($add, 3), ".", "") = "16" Or StringReplace(StringRight($add, 3), ".", "") = "23" Or StringReplace(StringRight($add, 3), ".", "") = "30" Then $add &= "We" If StringReplace(StringRight($add, 3), ".", "") = "3" Or StringReplace(StringRight($add, 3), ".", "") = "10" Or StringReplace(StringRight($add, 3), ".", "") = "17" Or StringReplace(StringRight($add, 3), ".", "") = "24" Or StringReplace(StringRight($add, 3), ".", "") = "31" Then $add &= "Tu" If StringReplace(StringRight($add, 3), ".", "") = "4" Or StringReplace(StringRight($add, 3), ".", "") = "11" Or StringReplace(StringRight($add, 3), ".", "") = "18" Or StringReplace(StringRight($add, 3), ".", "") = "25" Or StringReplace(StringRight($add, 3), ".", "") = "32" Then $add &= "Fr" If StringReplace(StringRight($add, 3), ".", "") = "5" Or StringReplace(StringRight($add, 3), ".", "") = "12" Or StringReplace(StringRight($add, 3), ".", "") = "19" Or StringReplace(StringRight($add, 3), ".", "") = "26" Then $add &= "Sa" If StringReplace(StringRight($add, 3), ".", "") = "6" Or StringReplace(StringRight($add, 3), ".", "") = "13" Or StringReplace(StringRight($add, 3), ".", "") = "20" Or StringReplace(StringRight($add, 3), ".", "") = "27" Then $add &= "Sn" If StringReplace(StringRight($add, 3), ".", "") = "7" Or StringReplace(StringRight($add, 3), ".", "") = "14" Or StringReplace(StringRight($add, 3), ".", "") = "21" Or StringReplace(StringRight($add, 3), ".", "") = "28" Then $add &= "Mn" ExitLoop EndIf EndIf Next Return $add EndFunc ;==>PDate Edited February 11, 2022 by ad777 iam ِAutoit programmer. best thing in life is to use your Brain to Achieve everything you want. Link to comment Share on other sites More sharing options...
junkew Posted February 11, 2022 Share Posted February 11, 2022 or just like this without any inputbox #include <DateTimeConstants.au3> #include <Date.au3> local $today=_NowCalcDate ( ) ;~ Todays date local $date1=_dateadd('D',-@WDay+1,$today) ;~Calculate the date of the monday in the week you run this local $date2=_dateadd('D',+13,$date1) ;~ Just add 13 days ;~ Just to show during debug consolewrite($today & @CRLF) consolewrite($date1 & @CRLF) consolewrite($date2 & @CRLF) ;~ Reformat local $strDate1=stringreplace($date1,"/",".") & ".Sun" local $strDate2=stringreplace($date2,"/",".") & ".Sat" local $newFolderName=$strdate1 & "-" & $strDate2 consolewrite($newFolderName & @CRLF) ;~ Create the folder DirCreate($newFolderName) FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now