Scite 备份文件 |
|
OnBeforeSave 事件,并在保存正在保存的文件时创建旧版本的备份。脚本使用一个简单的循环来复制文件的内容,而不是调用外部命令来完美复制原始文件,但这样做会丢失自定义属性和其他元数据。如果您需要精确的备份,请考虑执行外部命令来进行精确复制。此脚本使用 SciteExtMan。
-- NOTE: uses extman.lua -- Limitations: silently fails, does not copy metadata local function backupDeFile(fname) local BLK = 1024 * 64 bkname = fname.."~" local inf = io.open(fname, "rb") local outf = io.open(bkname, "wb") if not inf or not outf then return end while true do local dat = inf:read(BLK) if not dat then break end outf:write(dat) end inf:close() outf:close() end scite_OnBeforeSave(backupDeFile)
-- KeinHongMan
如果您只想一种简单的方式来创建当前文件的备份,还可以将以下内容添加到您的 SciTEGlobal.properties 中。
command.name.1.*=Backup this file command.1.*=dostring os.execute("cmd /C copy $(FileNameExt?) $(FileName?)_"..os.date("%y%m%d%H%M")..".$(FileExt?)") command.mode.1.*=subsystem:lua,savebefore:no
-- Alan MN