HahlefKazumoto Posted March 19, 2013 Share Posted March 19, 2013 Hi Everyone, i've just startet to script with AutoIT and im not realy used in the syntax of it too I would like to "detect" the newest file in a spezific folder, take it and rename it (filemove) with a value i discript before.. by google i found a function from another user. I think this function is exactly doing what i want.. but i dont get, how i could get the value (variable?) out of the function and use be able to use it.. Here you can see my Script: expandcollapse popupFunc EvaluateFiles($Folder) $avFiles = _FileListToArray($Folder & "\", "*",1) If @Error<>0 Then Return EndIf $iNewestTime = 11111111111111; YYYYMMDDhhmmss $iNewestIndex = 0; Array index of newest file ; Find the newest file For $p = 1 To $avFiles[0] $iFileTime2 = Number(FileGetTime($Folder & "\" & $avFiles[$p], 0, 1)) If $iFileTime2 > $iNewestTime Then $iNewestTime = $iFileTime2 $iNewestIndex = $p EndIf Next If $iNewestIndex > 0 Then $t = FileGetTime($Folder & "\" & $avFiles[$iNewestIndex]) $iDateCalc = _DateDiff( 'd',$t[0] & "/" & $t[1] & "/" & $t[2] & " " & $t[3] & ":" & $t[4] & ":" & $t[5],_NowCalc()) If $iDateCalc > 0 Then;<---Flags files that are older than today MsgBox(16,"ATTENTION","This files in - " & $Folder & " - have not been updated today." & @CRLF & @CRLF & $avFiles[$iNewestIndex] & " is the newest file with a modified date of" & @CRLF & @CRLF & $t[1] & "/" & $t[2] & "/" & $t[0] & " " & $t[3] & ":" & $t[4] & ":" & $t[5]) EndIf Else MsgBox(16, "Error", "Failed to find a newest file.") EndIf EndFunc $date1 = StringRight(@YEAR, 2) $date9 = $date1 & @MON & @MDAY & @HOUR & @MIN & @SEC $Fileformat1 = "ENG"&$date9&"C0Q002001" $Fileformat2 = "ENG"&$date9&"C0Q002002" $file = ("C:\Users\sx40211\desktop\Vorhanden\"&$Folder&".xlsx") $file2 = ("C:\Users\sx40211\desktop\Vorhanden\Neue Datei\"&$Fileformat1&".xlsx") FileMove($file, $file2, 1) Realy? i dont get it ^^ im sure, that i have to call the function, to get a value.. Call("EvaluateFiles") right? But how could i get now the name of the newest file? Please help me anyone... my head is exploding Link to comment Share on other sites More sharing options...
water Posted March 19, 2013 Share Posted March 19, 2013 Start by searching the forum! Use something like "newest file", select "Only search in titles" and you will get a lot of hits. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
HahlefKazumoto Posted March 19, 2013 Author Share Posted March 19, 2013 I tried as you told and i didnt get any results.. Link to comment Share on other sites More sharing options...
water Posted March 19, 2013 Share Posted March 19, 2013 That's what I get: My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
HahlefKazumoto Posted March 19, 2013 Author Share Posted March 19, 2013 jep jep, sry now a have some results to... thanks a lot for the time you spend.. Link to comment Share on other sites More sharing options...
water Posted March 19, 2013 Share Posted March 19, 2013 Glad to be of service We will be happy to answer further questions you might have. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
AutoBert Posted March 19, 2013 Share Posted March 19, 2013 Try this:expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_UseUpx=n #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include-once #include <Array.au3> #include <Date.au3> #include <File.au3> ;=============================================================================== ; Function Name: _FileListToArrayBetweenDates($sFolder, $sdateStart, $sdateEnd) ; Description:: returns the files between $sdateStart and $sdateEnd (start and enddate are included) ; ; Parameter(s): $sFolder = folder which is searched ; $sdateStart = the oldest date of filemodification to be returned ; $sdateEnd = the youngest date of filemodification to be returned ; ; Requirement(s): AutoIt 3.3.0.0 ; ; Return Value(s): 2D Array with filename(s) and modificationdate ; ; Author(s): autoBert (www.autoit.de) ;=============================================================================== Func _FileListToArrayBetween2Days($sFolder, $sdateStart = "", $sdateEnd = "") ; If $sdateEnd = "" Then $sdateEnd = @YEAR & @MON & @MDAY If $sdateEnd = "" Then $sdateEnd = '99991231' Dim $aRes2D[1][2] $aRes = _FileListToArray($sFolder,'*',1) ;All Files If Not IsArray($aRes) Then SetError(-1) Else $j = 0 ;Counter for Resultarray ReDim $aRes2D[$aRes[0] + 1][2] For $i = 1 To $aRes[0] $sFileDate = FileGetTime($sFolder & "\" & $aRes[$i], 0, 1) ;ConsoleWrite($aRes[$i] & @TAB & $sFileDate & @CRLF) If $sFileDate >= $sdateStart And $sFileDate <= $sdateEnd Then $j += 1 $aRes2D[$j][0] = $aRes[$i] $aRes2D[$j][1] = $sFileDate EndIf Next $aRes2D[0][0] = $j ReDim $aRes2D[$j + 1][2] _ArraySort($aRes2D, 1, 1, 0, 1) $aRes2D[0][1] = 'last modified' EndIf Return $aRes2D EndFunc ;==>_FileListToArrayBetween2Days ;Example: ;#cs Global $a2D $a2D = _FileListToArrayBetween2Days(@ScriptDir);creates a 2D-Array from beginn to end ConsoleWrite('The last modified file: '&$a2D[1][0]&@TAB&'modified: ' &$a2D[1][1]&@CRLF) _ArrayDisplay($a2D) ;#ceand modify to your needs 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