Alpinestar Posted August 14, 2009 Share Posted August 14, 2009 Hello Been using this function for quite some time, but recently changed it to my latest project (install sql express 2008), it is runs but does not return the latest log file.... The log file thats generated from the installation will be unqiue on the time date you run it, reason for all the ????. This is also the case with the folder. Help >_< expandcollapse popup$file = ("Summary_"& @ComputerName &"_????????_??????_GlobalRules.txt") $FindLog = _FileGetNewest("C:\Program Files\Microsoft SQL Server\100\Setup Bootstrap\Log", 0, 1, $file) MsgBox(9,"Info", " Found : " & $FindLog[0]) ;Function to Search all Sub Folders for a file ; --------------------------------------- ; Function _FileGetNewest() ; Call with: _FileGetNewest($sDirPath [, $iDateType [, $iRecurse [, $sPattern]]]) ; Where: $sDirPath is the directory to search ; $iDateType (0ptional) is the type of date to use: ; -3 = (oldest) Modified ; -2 = (oldest) Created ; -1 = (oldest) Accessed ; 0 = Newest Modified (default) ; 1 = Newest Created ; 2 = Newest Accessed ; $iRecurse (Optional): If non-zero causes the search to be recursive. ; $sPattern (Optional): Wildcard pattern for matching ; On success returns a 2-element array where: ; [0] = the full path to the newest file found ; [1] = the date/time stamp of the file "YYYYMMDDhhmmss" [from FileGetTime()] ; On failure returns 0, sets @error and @extended (see code below). ; Author: PsaltyDS ; --------------------------------------- Func _FileGetNewest($sDirPath, $iDateType = 0, $iRecurse = 0, $sPattern = '*.*') Local $avNewest[2] = ["", 0]; [0] = file path, [1] = time stamp Local $flagNewest = True, $iModDateType = $iDateType Local $hFirst, $sFound, $iFileTime Local $hSubDirs, $sSubdir, $avFoundRecurse If StringRight($sDirPath, 1) <> '\' Then $sDirPath &= '\' If Not FileExists($sDirPath) Then Return SetError(1, 0, 0) If $iDateType < -3 Or $iDateType > 2 Then Return SetError(1, 1, 0) If $iDateType < 0 Then $iModDateType = $iDateType + 3 $flagNewest = False EndIf ; Start search for files in this dir $hFirst = FileFindFirstFile($sDirPath & $sPattern) If ($hFirst <> -1) And (@error = 0) Then While 1 $sFound = FileFindNextFile($hFirst) If @error Then ExitLoop $iFileTime = FileGetTime($sDirPath & $sFound, $iDateType, 1) If ($avNewest[1] = 0) Or _ (($flagNewest = True) And ($iFileTime > $avNewest[1])) Or _ (($flagNewest = False) And ($iFileTime < $avNewest[1])) Then $avNewest[0] = $sDirPath & $sFound $avNewest[1] = $iFileTime EndIf WEnd EndIf FileClose($hFirst) ; Search subdirectories, if $iRecurse is set If $iRecurse Then $hSubDirs = FileFindFirstFile($sDirPath & '*.*') If ($hSubDirs <> -1) And (@error = 0) Then While 1 ; Start search for subdirectories $sSubdir = FileFindNextFile($hSubDirs) If @error = 0 Then ; Only recurse to directories If StringInStr(FileGetAttrib($sDirPath & $sSubdir), "D") Then ; Search a subdirectory $avFoundRecurse = _FileGetNewest($sDirPath & $sSubdir, $iDateType, $iRecurse, $sPattern) If @error Then ; Nothing found ContinueLoop Else ; Check if newest If $avFoundRecurse[1] > $avNewest[1] Then $avNewest = $avFoundRecurse If ($avNewest[1] = 0) Or _ (($flagNewest = True) And ($avFoundRecurse[1] > $avNewest[1])) Or _ (($flagNewest = False) And ($avFoundRecurse[1] < $avNewest[1])) Then $avNewest = $avFoundRecurse EndIf EndIf EndIf Else ; Done looking for subdirs ExitLoop EndIf WEnd EndIf EndIf If $avNewest[1] = 0 Then Return SetError(2, 0, 0); None found Else Return $avNewest EndIf EndFunc ;==>_FileGetNewest Link to comment Share on other sites More sharing options...
Alpinestar Posted August 15, 2009 Author Share Posted August 15, 2009 Anyone ? Link to comment Share on other sites More sharing options...
Scriptonize Posted August 15, 2009 Share Posted August 15, 2009 (edited) Hi AlpineStar, Your function doesn't check the first found file (if I'm right), or am I missing something? Hi finds it, but doesn't check it. Edited August 15, 2009 by Scriptonize If you learn from It, it's not a mistake Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 15, 2009 Moderators Share Posted August 15, 2009 Scriptonize,FileFindFirstFile returns a search handle - you have to use FileFindNextFile to get all the file names within that handle.Alpinestar,PsaltyDS' code returns the correct file for me - as I expected. As the function works, and your syntax seems correct, my only thought is that your pattern (as defined in $file) is not matching - are you sure you have that right? I hesitate to ask, but that is all I can think of!M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Scriptonize Posted August 15, 2009 Share Posted August 15, 2009 Scriptonize, FileFindFirstFile returns a search handle - you have to use FileFindNextFile to get all the file names within that handle. Alpinestar, PsaltyDS' code returns the correct file for me - as I expected. As the function works, and your syntax seems correct, my only thought is that your pattern (as defined in $file) is not matching - are you sure you have that right? I hesitate to ask, but that is all I can think of! M23 You are right. I figured that out just after posting in here. Thank you. |-) @AlpineStar When I change the line: MsgBox(9,"Info", " Found : " & $FindLog[0]) into..... MsgBox(0,"Info", " Found : " & $FindLog[0]) I have a positive result as wel. If you learn from It, it's not a mistake Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 15, 2009 Moderators Share Posted August 15, 2009 Scriptonize,I think you have found the answer! >_< It seems MsgBox will just fail with an invalid flag, without any error message.M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Alpinestar Posted August 15, 2009 Author Share Posted August 15, 2009 Thanks guys.... You knocked it on the head. >_< Link to comment Share on other sites More sharing options...
Scriptonize Posted August 15, 2009 Share Posted August 15, 2009 Glad your problem has been solved >_ If you learn from It, it's not a mistake 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