Noviceatthis Posted March 30, 2013 Posted March 30, 2013 Hello all I want to write a script to run on startup that checks all text files in a folder and looks at the dates therein, then compare it to the current day. $Path = @AppDataDir & "\Birthdays" if FileExists($Path) Then Sleep(20) Else DirCreate($Path) EndIf Local $search = FileFindFirstFile($Path & "\*.txt") Local $file = FileFindNextFile($search) $date = FileReadLine($file, 1) $nowdate = @MDAY & "/" & @MON & "/" & @YEAR if $date = $nowdate Then MsgBox(0, "Birthdays", "It is" & $file & "'s Birthday Today") EndIf Thats what I've written but its not working, where am I going wrong?? thanks in advance
FireFox Posted March 30, 2013 Posted March 30, 2013 Hi, FileFindNextFile returns a filename, so if you want to read its content you need to include its path. $date = FileReadLine($Path & "\" & $file, 1) And what's the Sleep for ? Br, FireFox.
Noviceatthis Posted March 30, 2013 Author Posted March 30, 2013 Thanks firefox and yeh having looked again, i could have just put: if not fileexists
Noviceatthis Posted March 31, 2013 Author Posted March 31, 2013 I am now further on in the script and i've hit another wall (I think i'm stepping over the boundaries of my current abilities with this one) expandcollapse popupHotKeySet("!+d", "gui1") $v = 0 TrayTip("", "Press: Shift + Alt + d to add a new birthday", 10) Global $Path = @AppDataDir & "\Birthdays" If Not FileExists($Path) Then DirCreate($Path) EndIf While $v <> 9 Global $search = FileFindFirstFile($Path & "\*.txt") Global $file = FileFindNextFile($search) $name = FileReadLine($Path & "\" & $file, 1) $date = FileReadLine($Path & "\" & $file, 2) $nowdate = @MDAY & "/" & @MON If $date = $nowdate Then MsgBox(0, "Birthdays", "It is " & $name & "'s Birthday Today") EndIf FileClose($search) $v = $v + 1 Sleep(1000) WEnd Exit Func gui1() #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #region ### START Koda GUI section ### Form= $Form1_1 = GUICreate("Form1", 616, 282, 238, 116) GUISetBkColor(0xA6CAF0) $Label1 = GUICtrlCreateLabel("Add Birthday", 0, 0, 612, 49, BitOR($SS_CENTER, $SS_CENTERIMAGE, $SS_SUNKEN)) GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif") GUICtrlSetBkColor(-1, 0xC0DCC0) $Label2 = GUICtrlCreateLabel("Full Name", 8, 72, 107, 24, BitOR($SS_CENTER, $SS_CENTERIMAGE, $SS_SUNKEN)) GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif") GUICtrlSetBkColor(-1, 0xC0DCC0) $Input1 = GUICtrlCreateInput("", 8, 104, 577, 24) GUICtrlSetFont(-1, 11, 400, 0, "MS Sans Serif") $Label3 = GUICtrlCreateLabel("Date of Birthday (DD/MM)", 8, 152, 200, 24, BitOR($SS_CENTER, $SS_CENTERIMAGE, $SS_SUNKEN)) GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif") GUICtrlSetBkColor(-1, 0xC0DCC0) $Input2 = GUICtrlCreateInput("", 8, 192, 577, 24) GUICtrlSetFont(-1, 11, 400, 0, "MS Sans Serif") $Button1 = GUICtrlCreateButton("Process", 200, 232, 225, 41) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") GUISetState(@SW_SHOW) #endregion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 $name123 = GUICtrlRead($Input1) $date123 = GUICtrlRead($Input2) FileOpen($Path & "\" & $name123 & ".txt", 1) FileWriteLine($Path & "\" & $name123 & ".txt", $name123) FileWriteLine($Path & "\" & $name123 & ".txt", $date123) FileClose($Path & "\" & $name123 & ".txt") GUICtrlSetData($Input1, "") GUICtrlSetData($Input2, "") EndSwitch WEnd EndFunc ;==>gui1 The script cannot pass the first birthday text file and I cant figure out why
FireFox Posted March 31, 2013 Posted March 31, 2013 Without running your script I see something strange. You are starting a filesearch each time in your loop without looping through files. The FileFindFirstFile function returns a filesearch handle, then you have to call the FileFindNextFile function until this one returns an error, meaning there is no more file. You should read carefully the help file, otherwise you wouldn't have asked this kind of questions. Br, FireFox.
Noviceatthis Posted March 31, 2013 Author Posted March 31, 2013 Thanks Firefox, I shouldve seen that This now works: expandcollapse popupHotKeySet("!+d", "gui1") $v = 0 TrayTip("", "Press: Shift + Alt + d to add a new birthday", 10) Global $Path = @AppDataDir & "\Birthdays" Global $otherpath = @AppDataDir & "\Birthdays\Birthdays2" If Not FileExists($Path) Then DirCreate($Path) EndIf If Not FileExists($otherpath) Then DirCreate($otherpath) EndIf While 1 Global $search = FileFindFirstFile($Path & "\*.txt") Global $file = FileFindNextFile($search) If @error = 1 Then ExitLoop Else Sleep(1000) EndIf $name = FileReadLine($Path & "\" & $file, 1) $date = FileReadLine($Path & "\" & $file, 2) $nowdate = @MDAY & "/" & @MON If $date = $nowdate Then MsgBox(0, "Birthdays", "It is " & $name & "'s Birthday Today") EndIf FileClose($search) $v = $v + 1 Sleep(1000) FileMove ($Path & "\" & $file, $otherpath & "\" & $file) sleep(1000) WEnd While 1 Global $search = FileFindFirstFile($otherpath & "\*.txt") Global $file = FileFindNextFile($search) If @error = 1 Then ExitLoop Else Sleep(1000) EndIf FileMove ($otherpath & "\" & $file, $Path & "\" & $file) sleep(1000) WEnd Sleep(10000) Exit Func gui1() #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #region ### START Koda GUI section ### Form= $Form1_1 = GUICreate("Form1", 616, 282, 238, 116) GUISetBkColor(0xA6CAF0) $Label1 = GUICtrlCreateLabel("Add Birthday", 0, 0, 612, 49, BitOR($SS_CENTER, $SS_CENTERIMAGE, $SS_SUNKEN)) GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif") GUICtrlSetBkColor(-1, 0xC0DCC0) $Label2 = GUICtrlCreateLabel("Full Name", 8, 72, 107, 24, BitOR($SS_CENTER, $SS_CENTERIMAGE, $SS_SUNKEN)) GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif") GUICtrlSetBkColor(-1, 0xC0DCC0) $Input1 = GUICtrlCreateInput("", 8, 104, 577, 24) GUICtrlSetFont(-1, 11, 400, 0, "MS Sans Serif") $Label3 = GUICtrlCreateLabel("Date of Birthday (DD/MM)", 8, 152, 200, 24, BitOR($SS_CENTER, $SS_CENTERIMAGE, $SS_SUNKEN)) GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif") GUICtrlSetBkColor(-1, 0xC0DCC0) $Input2 = GUICtrlCreateInput("", 8, 192, 577, 24) GUICtrlSetFont(-1, 11, 400, 0, "MS Sans Serif") $Button1 = GUICtrlCreateButton("Process", 200, 232, 225, 41) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") GUISetState(@SW_SHOW) #endregion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 $name123 = GUICtrlRead($Input1) $date123 = GUICtrlRead($Input2) FileOpen($Path & "\" & $name123 & ".txt", 1) FileWriteLine($Path & "\" & $name123 & ".txt", $name123) FileWriteLine($Path & "\" & $name123 & ".txt", $date123) FileClose($Path & "\" & $name123 & ".txt") GUICtrlSetData($Input1, "") GUICtrlSetData($Input2, "") EndSwitch WEnd EndFunc ;==>gui1 Not sure if this is the best way of going about this, but works for me
FireFox Posted March 31, 2013 Posted March 31, 2013 Rewritten code (without the gui1 func) : expandcollapse popup#include <Constants.au3> ;~ HotKeySet("!+d", "gui1") TrayTip("", "Press: Shift + Alt + d to add a new birthday", 10) Local Const $sBirthDir = @AppDataDir & "\Birthdays" Local Const $sBirth2Dir = @AppDataDir & "\Birthdays\Birthdays2" If FileExists($sBirthDir) = 0 Then DirCreate($sBirthDir) EndIf If FileExists($sBirth2Dir) = 0 Then DirCreate($sBirth2Dir) EndIf Local $hSearch = 0, $sFileFullname = "" Local $sName = "", $sDate = "" Local Const $sNowDate = @MDAY & "/" & @MON While 1 $hSearch = FileFindFirstFile($sBirthDir & "\*.txt") If $hSearch = -1 Then ExitLoop $sFileFullname = FileFindNextFile($hSearch) If @error = 1 Then FileClose($hSearch) ExitLoop EndIf $sName = FileReadLine($sBirthDir & "\" & $sFileFullname, 1) $sDate = FileReadLine($sBirthDir & "\" & $sFileFullname, 2) If $sDate = $sNowDate Then MsgBox($MB_APPLMODAL, "Birthdays", "It is " & $sName & "'s Birthday Today") EndIf FileMove($sBirthDir & "\" & $sFileFullname, $sBirth2Dir & "\" & $sFileFullname) Sleep(10) WEnd While 1 $hSearch = FileFindFirstFile($sBirth2Dir & "\*.txt") If $hSearch = -1 Then ExitLoop $sFileFullname = FileFindNextFile($hSearch) If @error = 1 Then FileClose($hSearch) ExitLoop EndIf FileMove($sBirth2Dir & "\" & $sFileFullname, $sBirthDir & "\" & $sFileFullname) Sleep(10) WEnd
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