sconley Posted March 6, 2005 Share Posted March 6, 2005 Is there a way have SciTE to save the previous version of a file when it saves the new file? The other script editors I have used save at least 1 and usually several previous versions of files. Link to comment Share on other sites More sharing options...
Developers Jos Posted March 6, 2005 Developers Share Posted March 6, 2005 Is there a way have SciTE to save the previous version of a file when it saves the new file?The other script editors I have used save at least 1 and usually several previous versions of files.<{POST_SNAPBACK}>This can be done with a LUA script.Add this code to AutoIt3.LUA and the file will always be moved to "filename".bak before the new version is saved.function OnBeforeSave(filename) os.remove (filename..".bak") os.rename (filename, filename..".bak") return false endI can add it to the standard installer when ppl find this useful .... 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 March 6, 2005 Developers Share Posted March 6, 2005 Will add the below LUA script to AutoIt3.LUA to facilitate to save backups of your Autoit3 script. It will be configurable by specifying the following in your SciTeUser.properties: #define the number of backup files you want to keep 0=none backup.files=3 function OnBeforeSave(filename) local sbck = tonumber(props['backup.files']) -- no backup specified if sbck == nil or sbck == 0 then return false end local nbck = 1 while (sbck > nbck ) do local fn1 = sbck-nbck local fn2 = sbck-nbck+1 os.remove (filename.. "." .. fn2 .. ".bak") if fn1 == 1 then os.rename (filename .. ".bak", filename .. "." .. fn2 .. ".bak") else os.rename (filename .. "." .. fn1 .. ".bak", filename .. "." .. fn2 .. ".bak") end nbck = nbck + 1 end os.remove (filename.. "." .. ".bak") os.rename (filename, filename .. ".bak") 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...
sconley Posted March 7, 2005 Author Share Posted March 7, 2005 Thanks... The code worked fine... Link to comment Share on other sites More sharing options...
sconley Posted March 13, 2005 Author Share Posted March 13, 2005 After looking at your code, I became a little interested in Lua.I modified the code to create the backups in a different folder on the same drive as the original source and I used ".1.bak" for the first backup instead of ".bak".There was nothing wrong with your code...I just started playing with Lua to see what I could do.expandcollapse popup-- function OnBeforeSave(filename) local sbck = tonumber(props['backup.files']) -- no backup specified if sbck == nil or sbck == 0 then return false end local my_backup_path = (props['backup.path']) if (my_backup_path == nil) or (my_backup_path == 0) then my_backup_path = "d:\\Sci-TE-Backup" end -- Determine where to store the backups local my_loc_of_last_backslash = (string.find(filename,"[^%\\]*$",1)) if my_loc_of_last_backslash == nil then return false end my_loc_of_last_backslash = my_loc_of_last_backslash - 1 -- Extract the last part of the filename local my_filename = string.sub(filename,my_loc_of_last_backslash + 1,-1) -- Extract the drive letter my_drive_letter = string.sub(filename,1,2) -- Format complete path to location where backups will be stored my_backup_path = my_drive_letter .. string.sub(my_backup_path,3,-1) -- Shift existing backups up by 1 local my_tmp_filename1 = '' local my_tmp_filename2 = '' local my_index = sbck while (my_index >= 1) do my_tmp_filename1 = my_backup_path .. "\\" .. my_filename .. "." .. my_index .. ".bak" os.remove(my_tmp_filename1) if my_index ~= 1 then my_tmp_filename2 = my_backup_path .. "\\" .. my_filename .. "." .. (my_index - 1) .. ".bak" os.rename(my_tmp_filename2, my_tmp_filename1) end my_index = my_index - 1 end -- Rename the original file to .1.bak my_tmp_filename2 = my_backup_path .. "\\" .. my_filename .. ".1.bak" os.rename(filename, my_tmp_filename1) return false endWill add the below LUA script to AutoIt3.LUA to facilitate to save backups of your Autoit3 script. It will be configurable by specifying the following in your SciTeUser.properties:#define the number of backup files you want to keep 0=none backup.files=3function OnBeforeSave(filename) local sbck = tonumber(props['backup.files']) -- no backup specified if sbck == nil or sbck == 0 then return false end local nbck = 1 while (sbck > nbck ) do local fn1 = sbck-nbck local fn2 = sbck-nbck+1 os.remove (filename.. "." .. fn2 .. ".bak") if fn1 == 1 then os.rename (filename .. ".bak", filename .. "." .. fn2 .. ".bak") else os.rename (filename .. "." .. fn1 .. ".bak", filename .. "." .. fn2 .. ".bak") end nbck = nbck + 1 end os.remove (filename.. "." .. ".bak") os.rename (filename, filename .. ".bak") return false end<{POST_SNAPBACK}> Link to comment Share on other sites More sharing options...
Developers Jos Posted March 13, 2005 Developers Share Posted March 13, 2005 After looking at your code, I became a little interested in Lua.I modified the code to create the backups in a different folder on the same drive as the original source and I used ".1.bak" for the first backup instead of ".bak".There was nothing wrong with your code...I just started playing with Lua to see what I could do.<{POST_SNAPBACK}>Didn't have much time to look at this but just a couple of observations/questions:- Will it also work when the "backup" directory doesn't exists?- I think it should default to the script directory when the 'backup.path' isn't defined. 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...
MHz Posted March 13, 2005 Share Posted March 13, 2005 (edited) Tidy does a good backup plan. Also CompileAU3 can backup files to another folder. But then, not all the editors have Tidy or CompileAU3. Edited March 13, 2005 by MHz Link to comment Share on other sites More sharing options...
sconley Posted March 13, 2005 Author Share Posted March 13, 2005 I couldn't figure out how to create the backup directory in LUA in a direct manner, but I do believe I have it working...it does show a flash of a black DOS window if it has to create the directory.The backup probably should default to the source directory. I was having so so so many backups in my source directory that it became unmanageable. I put code in to have it default to the source filename's directory.I made a couple of changes (I left the my_ prefix in front of what I added):expandcollapse popup-- function OnBeforeSave(filename) local sbck = tonumber(props['backup.files']) -- no backup specified if sbck == nil or sbck == 0 then return false end -- Find the last backslash in filename in order to format a path to the backup folder local my_loc_of_last_backslash = (string.find(filename,"[^%\\]*$",1)) if my_loc_of_last_backslash == nil then return false end my_loc_of_last_backslash = my_loc_of_last_backslash - 1 -- Extract the last part of the filename local my_filename = string.sub(filename,my_loc_of_last_backslash + 1,-1) -- Extract the drive letter local my_drive_letter = string.sub(filename,1,2) -- Extract filename's path local my_path = string.sub(filename,1,my_loc_of_last_backslash - 1) -- Retrieve path to backup folder from properties file. Default to filename's path. local my_backup_path = (props['backup.path']) if (my_backup_path == nil) or (my_backup_path == 0) then my_backup_path = my_path end -- Format complete path to location where backups will be stored. Create path if it does not exist my_backup_path = my_drive_letter .. string.sub(my_backup_path,3,-1) if (os.rename(my_backup_path,my_backup_path)) == nil then os.execute('mkdir "' .. my_backup_path .. '"') end -- Shift existing backups up by 1 local my_tmp_filename1 = '' local my_tmp_filename2 = '' local my_index = sbck while (my_index >= 1) do my_tmp_filename1 = my_backup_path .. "\\" .. my_filename .. "." .. my_index .. ".bak" os.remove(my_tmp_filename1) if my_index ~= 1 then my_tmp_filename2 = my_backup_path .. "\\" .. my_filename .. "." .. (my_index - 1) .. ".bak" os.rename(my_tmp_filename2, my_tmp_filename1) end my_index = my_index - 1 end -- Rename the original file to .1.bak my_tmp_filename2 = my_backup_path .. "\\" .. my_filename .. ".1.bak" os.rename(filename, my_tmp_filename1) return false endDidn't have much time to look at this but just a couple of observations/questions:- Will it also work when the "backup" directory doesn't exists?- I think it should default to the script directory when the 'backup.path' isn't defined.<{POST_SNAPBACK}> 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