Page 1 of 1

[script] Simple Backup System for RJ TE

Posted: 29 Jan 2015 17:35
by pjj
Thanks to Rickard's fantastic support for script development (and his terrific editor in general!), I am now able to present quite elaborated script for backing up your source files, hoping you will find it useful.

Goal of Simple Backup System for RJ TextEdit (SBS) is to store, depending on your configuration and backup mode you've chosen, all or some files located in a given project directory and its subdirectories. The archive is saved into #backup subdirectory. There are two modes for backup: full and partial. Archive files have timestamps in their names, and each run (backup type, date & time, comment) is also logged into a text file for a quick reference. -- This is, of course, not a full-blown versioning system, but I hope it will come in handy nevertheless.

I tried to painstakingly describe everything related to SBS, so please refer to readme.txt file contained in the SBS archive, available to download below. Please notice that you need RJ TE in version at least 10.20 to run this script.
(5.98 KiB) Downloaded 528 times
(re-uploaded to the new forum; previously downloaded 15 times)

If you have any comments or feature requests, please write them in this thread.

SBS is licensed as beerware :wink:

Re: [script] Simple Backup System for RJ TE

Posted: 25 Apr 2018 07:53
by pjj
Funny thing, but if you run backup script before noon, with some locales filename could be corrupted: time part (and, which is worse, file extension) could be completely omitted due to a space leading hour digit (instead of 0); to correct this, just change one line:

Code: Select all

SET archive_name=%date:/=%@%time:~0,2%h%time:~3,2%m
with these two:

Code: Select all

FOR /F "tokens=1-2 delims=/: " %%a in ("%TIME%") DO (if %%a LSS 10 (SET time=0%%ah%%bm) else (SET time=%%ah%%bm))
SET archive_name=%date:/=%@%time%

Re: [script] Simple Backup System for RJ TE

Posted: 14 Nov 2021 17:44
by Andreas
Hello PJJ,

I need a way more easier backup script and I'm not working with projects. I took a look at your script and thought I could change i to my needs. But I think it's to complicated for me. I'm a webdeveloper with knowledge of PHP, JavaScript ... but I don't know Fastscript and RJ TextEd is new to me.

Maybe you can find the time to change it for me|us or lead me to the right direction?

What I want to achieve is, that every time I save a file opened via FTP on the server, that TextEd automaticaly saves a copy of this file local with the appropriate folder structure as on the server. E.g.

Code: Select all

All I should have to do is to set a parent backup folder somewhere.

Do you think that this is possible with TextEd?

I worked for about 15 years with the editor PsPad. But this has now too many crashes, etc. And I'm looking for a new editor. PsPad had always automatically saved my open files as backup in a backup folder. This folder has always been a helpful collecturium in which I could search for old code snippets and old solutions. Unfortunately, I miss this option in RJ Texted.

Regards Andreas

Re: [script] Simple Backup System for RJ TE

Posted: 14 Nov 2021 22:56
by pjj
I'd love to help, but perhaps it would be feasible for you without any script? There's an option to save remote files locally (Options > Editor > File > Save remote files), but you need to pick location for each saved file.

If you decide that this is not what you want, sure, we can tackle the script. I guess it will be not too complicated: just find current directory, find backup directory based on this, save current file into the backup directory with date in its name -- and run this script when file is opened (or saved). Do you want to give it a try yourself? Or would you prefer that I do it?

One more thing: FastScript runs JavaScript (and three other languages), and what you saw in my script that indeed could have been a bit intimidating :wink: was just GUI. In this script we won't need any of this.

Re: [script] Simple Backup System for RJ TE

Posted: 17 Nov 2021 10:07
by pjj
After some tinkering I came up with something like this:

Code: Select all

var i, j;

var docNameFull = Document.FileName;
var docPath, docNameExt, docName, docExt;

i = ScriptUtils.RightPosFrom("\\", docNameFull, 999);
j = ScriptUtils.RightPosFrom(".", docNameFull, 999);
docPath = copy(docNameFull, 0, i);
docExt = copy(docNameFull, j + 1, 999);

docNameExt = copy(docNameFull, Length(docPath) + 1, 999);
docName = copy(docNameExt, 0, Length(docNameExt) - Length(docExt) - 1);

var now = DateToStr(Date()) + "_" + copy(TimeToStr(Time()), 0, 5);
now = ScriptUtils.StringReplaceAll(now, ":", "-");

var text = Document.Text;

// target file doesn't exist yet
Word mode = fmCreate or fmOpenReadWrite;

// save target file
TFileStream stream = TFileStream.Create(docPath + "#backup" + "\\" + docName + "_" + now + "." + docExt, mode);
try {
    stream.WriteString(text, encUTF8);
finally {
A couple of notices and caveats:
  • file must have extension (any)
  • #backup dir needs to be located in the same dir as the file
  • you can run this script manually or on document save; on document open it won't do anything, since document name etc. are not known yet
  • file is saved as UTF8, you can use encAnsi or encUnicode, too
  • you could use Document.SaveAsNoMRU and run script on document open, but then standard Windows dialog for saving would open and you still would need to click to go to your backup directory
I hope it will help you a bit, somehow :)