GAM Posted October 28, 2008 Share Posted October 28, 2008 Hi, I have a folder where new builds are copied everyday. Now my task is "HOW TO FIND THE LATEST FILE in that folder?" Help! Neil Link to comment Share on other sites More sharing options...
Andreik Posted October 28, 2008 Share Posted October 28, 2008 Hi, I have a folder where new builds are copied everyday. Now my task is "HOW TO FIND THE LATEST FILE in that folder?" Help!You need _FileListToArray() and FileGetTime(). Exists another examples on forum, try to search. Link to comment Share on other sites More sharing options...
monoceres Posted October 28, 2008 Share Posted October 28, 2008 Since the function is pretty easy to write, I made it for you. #include <File.au3> MsgBox(0, "", _FindLatest(@ScriptDir)) Func _FindLatest($dir) Local $latest[2] $files = _FileListToArray($dir, "*", 1) For $i = 1 To UBound($files) - 1 If FileGetTime($files[$i], 1, 1) > $latest[0] Or $i = 1 Then $latest[0] = FileGetTime($files[$i], 1, 1) $latest[1] = $i EndIf Next Return $files[$latest[1]] EndFunc ;==>_FindLatest AnonymousX 1 Broken link? PM me and I'll send you the file! Link to comment Share on other sites More sharing options...
zvvyt Posted June 16, 2012 Share Posted June 16, 2012 #include <File.au3> MsgBox(0, "", _FindLatest(@ScriptDir)) Func _FindLatest($dir) Local $latest[2] $files = _FileListToArray($dir, "*", 1) For $i = 1 To UBound($files) - 1 If FileGetTime($files[$i], 1, 1) > $latest[0] Or $i = 1 Then $latest[0] = FileGetTime($files[$i], 1, 1) $latest[1] = $i EndIf Next Return $files[$latest[1]] EndFunc ;==>_FindLatest Your code saved me some time, but I'm having a bit of a problem with it...: When I run the script from inside the folder I want to check this works like a charm, but once I add the exact same code into a script lying somewhere else and (ofc) changes the specified dir to a dir variable, the scrips just over and over gives me the same folder name! Even when I'm creating new folders into that same folder it will only give me the name of the (now) oldest folder and not the latest one. So in short: Code works when run from a script inside the folder to check, but not when used from a script in a distant folder (and yes, the @ScriptDir has been replaced with a variable for the dir path). Does anyone have an answer to this? Best regards, zvvyt Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 16, 2012 Moderators Share Posted June 16, 2012 zvvyt,I imagine that you need to add the full path to the filename when using FileGetTime so that it knows where to look. FileGetTime($dir & "" & $files[$i], 1, 1)Am I right? 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...
zvvyt Posted June 16, 2012 Share Posted June 16, 2012 Shit .. I totally forgot about that! >__<' You really eased my headache! Once again, thanks a lot M23! ^__^ Best regards, Link to comment Share on other sites More sharing options...
aisha Posted July 9, 2018 Share Posted July 9, 2018 On 6/16/2012 at 7:30 AM, Melba23 said: zvvyt, I imagine that you need to add the full path to the filename when using FileGetTime so that it knows where to look. FileGetTime($dir & "" & $files[$i], 1, 1) Am I right? M23 What is the $files variable doing? What should we initialize it to? How does the FileGetTime work? Link to comment Share on other sites More sharing options...
aisha Posted July 9, 2018 Share Posted July 9, 2018 What is $files variable doing? What should we initialize it to? How does _FileListToArray work here? Confused. Kindly help. Link to comment Share on other sites More sharing options...
careca Posted July 9, 2018 Share Posted July 9, 2018 $files Is the array for the file list $files[0] will be the total quantity of files $files[1] the first file, and so on only instead of numbers you have another variable that will increase in number so..there you go, loop though all files. Spoiler Renamer - Rename files and folders, remove portions of text from the filename etc. GPO Tool - Export/Import Group policy settings. MirrorDir - Synchronize/Backup/Mirror Folders BeatsPlayer - Music player. Params Tool - Right click an exe to see it's parameters or execute them. String Trigger - Triggers pasting text or applications or internet links on specific strings. Inconspicuous - Hide files in plain sight, not fully encrypted. Regedit Control - Registry browsing history, quickly jump into any saved key. Time4Shutdown - Write the time for shutdown in minutes. Power Profiles Tool - Set a profile as active, delete, duplicate, export and import. Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes. NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s. IUIAutomation - Topic with framework and examples Au3Record.exe 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