Vivaed Posted October 17, 2016 Share Posted October 17, 2016 I am trying to read all the files in a folder, then whatever file is newest, keep only that one and delete the rest. Example files: (these all have version numbers embedded in them, I dont want to rely on the file name) Faint.exe Faint-v2.0.exe Faint-v3.0.exe Faint-v4.0.exe What I have so far: #include <File.au3> RemoveOldFiles() ConsoleWrite(FileGetVersion("C:\WB Resources\FAINT_DONT_LINK_THESE\Faint-v4.0.0.exe") &@CRLF) Func RemoveOldFiles() Local $aFileList = _FileListToArray("C:\WB Resources\FAINT_DONT_LINK_THESE\", "*.exe",$FLTA_FILES) For $i = 0 To UBound($aFileList) - 1 $aFileVersion = FileGetVersion($aFileList[$i]) ConsoleWrite($aFileList[$i] & @CRLF) ConsoleWrite($aFileVersion & @CRLF) Next EndFunc OUTPUT: >Running:(3.3.14.2):C:\Program Files (x86)\AutoIt3\autoit3_x64.exe "C:\Users\bot\ownCloud\WellBeats\Delete Old Files\delete-test.au3" --> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop 3 0.0.0.0 a.exe 0.0.0.0 b.exe 0.0.0.0 Faint-v4.0.0.exe 0.0.0.0 4.0.0.18 <-- This is the correct file version.... +>07:34:26 AutoIt3.exe ended.rc:0 +>07:34:26 AutoIt3Wrapper Finished. >Exit code: 0 Time: 0.6647 Not sure what I am missing here? Thanks! Link to comment Share on other sites More sharing options...
l3ill Posted October 17, 2016 Share Posted October 17, 2016 (edited) Once you have your array ( have a look at it with _arrayDisplay) Arraysort so the highest number is at the end ArrayExtract nth element (last element) Sorry just need to read the last element... Edited October 17, 2016 by l3ill My Contributions... SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example Link to comment Share on other sites More sharing options...
Vivaed Posted October 17, 2016 Author Share Posted October 17, 2016 43 minutes ago, l3ill said: Once you have your array ( have a look at it with _arrayDisplay) Arraysort so the highest number is at the end ArrayExtract nth element (last element) Sorry just need to read the last element... Thanks for the info. The issue at this point is its not displaying the correct information, it returns 0.0.0.0 for all even if the version is 4.0.0.18 In my example I run the function, then I run the FileGetVersion on just on file and the two outputs are different. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 17, 2016 Moderators Share Posted October 17, 2016 Vivaed, I suspect you are getting that response because you are not passing the full path to FileGetVersion. Try using the $bReturnPath parameter when running _FileListToArray so that the returns contain the full path and see if you get the correct version number returned. 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...
l3ill Posted October 17, 2016 Share Posted October 17, 2016 (edited) Had some time to play, try this: #include <Array.au3> Global $aFileListVers[0] Local $aFileList = _FileListToArray("C:\WB Resources\FAINT_DONT_LINK_THESE\", "*.exe", $FLTA_FILES, True) For $i = 0 To UBound($aFileList) - 1 $aFileVersion = FileGetVersion($aFileList[$i], $FV_PRODUCTVERSION) _ArrayAdd($aFileListVers, $aFileVersion) Next _ArrayDisplay($aFileListVers) _ArraySort($aFileListVers, 1) _ArrayDisplay($aFileListVers) MsgBox(0, "Version", "Highest Version: " & $aFileListVers[0]) I did notice that not all exe's have a version as such that autoit can find it this way. So check yours first using Context Menu (Right Click) Properties/Details and look at Product Version. If its empty this will not produce anything. This one for instance has a File Version but no Product Version so you would have to change the FileGetVersion Parameter Edited October 18, 2016 by l3ill Vivaed 1 My Contributions... SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example 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