Developers Jos Posted July 6, 2020 Developers Share Posted July 6, 2020 (edited) This version will always have a 2 digit backup sequence number and rename any single digit to 2 digits. expandcollapse popup-------------------------------------------------------------------------------- -- run a cmd command and capture the output -------------------------------------------------------------------------------- function perform_oscommand(cmd) local handle=io.popen("" .. cmd) local consoleoutput = handle:read('*all') handle:close() return consoleoutput end -------------------------------------------------------------------------------- -- OnBeforeSave(filename) -- -- keep the number of backups as defined by backup.files = ? by Jos van der Zande (Jos) -- -- AutoItTools.OnBeforeSave -------------------------------------------------------------------------------- function AutoItTools:OnBeforeSave(filename) -- skip making the backup when file isn't changed if not editor.Modify then return false end local backupfiles = tonumber(props['backup.files']) -- backup specified and bigger than 0 ? if backupfiles == nil or backupfiles == 0 then return false end -- get file directory fdir = filename:match(".+[/\\]") fname = filename:match(".+[/\\](.+)") fext = fname:match(".+(%..+)") or "" if fext ~= "" then fname = fname:match("(.+)%..+") end -- set backup directory if props['backup.directory'] == "" then bdir = fdir .. "backup" -- no fixed backupdirectory location defined else bdir = props['backup.directory'] -- use the backupdirectory location defined for backup.directory end -- set backup rename to extra string. default Filename_bakx.Fileext if props['backup.renameto'] == "" then bmid = "_bak" -- default else bmid = props['backup.renameto'] -- use the backupdirectory location defined for backup.directory end -- ensure the backup directory exists perform_oscommand('mkdir "'..bdir..'"') -- -- check for all current existing backup files local currentbackupfiles = 1 local tfile = "" local fh=0 while (1) do tfile = bdir.."\\".. fname..bmid..currentbackupfiles..fext tfile2 = bdir.."\\".. fname..bmid..string.format("%02d",currentbackupfiles)..fext fh = io.open (tfile, "r") if fh == nil then fh = io.open (tfile2, "r") if fh == nil then break end io.close(fh) else io.close(fh) os.rename (tfile,tfile2) end currentbackupfiles = currentbackupfiles + 1 end -- move old backupfiles to 1 to (backupfiles-1) if backupfiles > 0 and backupfiles < currentbackupfiles then for y=1,currentbackupfiles-1 do y2 = y + backupfiles - currentbackupfiles local fn1 = bdir.."\\".. fname..bmid..string.format("%02d",y)..fext local fn2 = bdir.."\\".. fname..bmid..string.format("%02d",y2)..fext if currentbackupfiles - y < backupfiles then os.remove (fn2) os.rename (fn1,fn2) else os.remove (fn1) end end currentbackupfiles = backupfiles end local fn1 = bdir.."\\"..fname..bmid..string.format("%02d",currentbackupfiles)..fext os.remove (fn1) os.rename (filename, fn1) return false end This isn't implemented in Tidy yet, but will do so when the approach is firmed-up. Jos Edited August 10, 2020 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 6, 2020 Moderators Share Posted July 6, 2020 Jos, You have to code it so you choose how you want to denominate the backups. This "old dog" has had to learn quite a few "new tricks" over the years and I am quite sure I can cope with a new SciTE backup numbering system if necessary! 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...
Developers Jos Posted July 6, 2020 Developers Share Posted July 6, 2020 2 minutes ago, Melba23 said: You have to code it so you choose how you want to denominate the backups. That an option too ..... but requires an extra config option and more logic in both the above function and Tidy to cope with the 2 different logic's. SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 6, 2020 Moderators Share Posted July 6, 2020 Jos, I was not suggesting an option for the user! I was trying to say that I can live with whatever YOU decide YOU want to code! 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...
pseakins Posted July 6, 2020 Author Share Posted July 6, 2020 1 hour ago, Dan_555 said: Hi, i'm jumping into this with a request. Can you add leading 0 before the numbers ? So that the sorting order, (in my case i'm sorting the files by the extension, not by the date), be correct. Dan, this issue was addressed, at least in Windows Explorer, many versions ago. I believe there is a way to change the behaviour if required. Of course, the old dir command still lists files in the order you described but with Windows Explorer in my Windows 7 this is not a problem as it very cleverly treats the numeric portions of the file name/ext in ascending order. At first I thought this was a daft change by Microsoft but now I actually find it quite convenient. Phil Seakins Link to comment Share on other sites More sharing options...
pseakins Posted July 6, 2020 Author Share Posted July 6, 2020 34 minutes ago, Jos said: This version will always have a 2 digit backup sequence number and rename any single digit to 2 digits. Very nice Jos. (I actually would prefer three digits but I think I would probably be outvoted as even I can see that being a bit over the top). Phil Seakins Link to comment Share on other sites More sharing options...
Developers Jos Posted July 6, 2020 Developers Share Posted July 6, 2020 The 2 digit version number is now also implemented in the current Tidy Beta version 19.1127.1402.6. The naming convention is still fixed and the same: scriptname_oldxx.au3. Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Developers Jos Posted July 6, 2020 Developers Share Posted July 6, 2020 Both an update for SciTE.exe and AutoItTools.lua are available in Beta too. SciTE has the patch applied to suppress the popup box for os.execute. All you need to do is set this in SciTEUser,properties: create.hidden.console=1 let me know when you see issues. Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Dan_555 Posted July 6, 2020 Share Posted July 6, 2020 (edited) Quote Dan, this issue was addressed, at least in Windows Explorer Thanks, this reminded me to look, if FreeCommanderXE has that option, and it does ! Edited July 6, 2020 by Dan_555 Some of my script sourcecode Link to comment Share on other sites More sharing options...
Developers Jos Posted August 10, 2020 Developers Share Posted August 10, 2020 I had to make a small update as the Save-As would not save the file at all when there were no modifications. This was cause by returning a true in the first test. This version fixes that: expandcollapse popup-------------------------------------------------------------------------------- -- run a cmd command and capture the output -------------------------------------------------------------------------------- function perform_oscommand(cmd) local handle=io.popen("" .. cmd) local consoleoutput = handle:read('*all') handle:close() return consoleoutput end -------------------------------------------------------------------------------- -- OnBeforeSave(filename) -- -- keep the number of backups as defined by backup.files = ? by Jos van der Zande (Jos) -- -- AutoItTools.OnBeforeSave -------------------------------------------------------------------------------- function AutoItTools:OnBeforeSave(filename) -- skip making the backup when file isn't changed if not editor.Modify then return false end local backupfiles = tonumber(props['backup.files']) -- backup specified and bigger than 0 ? if backupfiles == nil or backupfiles == 0 then return false end -- get file directory fdir = filename:match(".+[/\\]") fname = filename:match(".+[/\\](.+)") fext = fname:match(".+(%..+)") or "" if fext ~= "" then fname = fname:match("(.+)%..+") end -- set backup directory if props['backup.directory'] == "" then bdir = fdir .. "backup" -- no fixed backupdirectory location defined else bdir = props['backup.directory'] -- use the backupdirectory location defined for backup.directory end -- set backup rename to extra string. default Filename_bakx.Fileext if props['backup.renameto'] == "" then bmid = "_bak" -- default else bmid = props['backup.renameto'] -- use the backupdirectory location defined for backup.directory end -- ensure the backup directory exists perform_oscommand('mkdir "'..bdir..'"') -- -- check for all current existing backup files local currentbackupfiles = 1 local tfile = "" local fh=0 while (1) do tfile = bdir.."\\".. fname..bmid..currentbackupfiles..fext tfile2 = bdir.."\\".. fname..bmid..string.format("%02d",currentbackupfiles)..fext fh = io.open (tfile, "r") if fh == nil then fh = io.open (tfile2, "r") if fh == nil then break end io.close(fh) else io.close(fh) os.rename (tfile,tfile2) end currentbackupfiles = currentbackupfiles + 1 end -- move old backupfiles to 1 to (backupfiles-1) if backupfiles > 0 and backupfiles < currentbackupfiles then for y=1,currentbackupfiles-1 do y2 = y + backupfiles - currentbackupfiles local fn1 = bdir.."\\".. fname..bmid..string.format("%02d",y)..fext local fn2 = bdir.."\\".. fname..bmid..string.format("%02d",y2)..fext if currentbackupfiles - y < backupfiles then os.remove (fn2) os.rename (fn1,fn2) else os.remove (fn1) end end currentbackupfiles = backupfiles end local fn1 = bdir.."\\"..fname..bmid..string.format("%02d",currentbackupfiles)..fext os.remove (fn1) os.rename (filename, fn1) return false end SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
pseakins Posted August 10, 2020 Author Share Posted August 10, 2020 11 hours ago, Jos said: I had to make a small update What did you update? The code in this post is identical to the earlier post on 7/6/20 On 7/6/2020 at 9:26 PM, Jos said: This version will always have a 2 digit backup sequence number Phil Seakins Link to comment Share on other sites More sharing options...
Developers Jos Posted August 11, 2020 Developers Share Posted August 11, 2020 mmm ... you are right it was correct in the posted code but wrong in my own version on my Laptop, like it was in the posted code a page back. ... guess I had a senior moment somewhere back then and didn't replace it with the correct version. 😕 Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. 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