I have a userscript which I have used for years which saves a copy of my file to a backup folder with a date and time added every time the file is updated and saved, this has worked fine up to now. I have just moved to windows 11 and it has suddenly stopped working and just gives an error.
I have tracked down the problem to the lines of code that check if the backup folder exists and if not creates it,
if (!osPath.exists(backup_fld)) {
os.mkdir(backup_fld);
ko.statusBar.AddMessage('Create folder '+backup_fld, ‘editor’, 5000, true);
}
if I remove that part, the script works and happily saves a copy of the file, this is OK with existing projects as the folders exist, but it would be nice to have that check/create back for new projects.
Anyone any idea why this should suddenly stop working under windows 11 when is was working under windows 10 using the same version of Komodo 12.0.1 build 91869.
As far as I can see the check for the existence of the folder incorrectly returns true so it tries to create a folder that already exists and falls over.
Full script below, this originally came from a post on this board way back.
Thanks
John
var os = Components.classes["@activestate.com/koOs;1"].getService(Components.interfaces.koIOs);
var basename = ko.views.manager.currentView.koDoc.file.baseName;
var curdir = ko.views.manager.currentView.koDoc.file.dirName;
var scimoz = ko.views.manager.currentView.scimoz;
var content = scimoz.text;
var date = new Date();
var Year = date.getFullYear();
var Month = date.getMonth();
var Day = date.getDate();
var Hour = date.getHours();
var Minute = date.getMinutes();
var Second = date.getSeconds();
if(Month<10) Month = “0” + Month;
if(Day<10) Day = “0” + Day;
if(Hour<10) Hour = “0” + Hour;
if(Minute<10) Minute = “0” + Minute;
if(Second<10) Second = “0” + Second;
var timestamp = Year+"-"+Month+"-"+Day+"-"+Hour+"-"+Minute+"-"+Second+"-";
var backup_fld = curdir+"_bak/";
var backup =backup_fld+timestamp+basename+".bak";
if (!osPath.exists(backup_fld)) {
os.mkdir(backup_fld);
ko.statusBar.AddMessage('Create folder '+backup_fld, ‘editor’, 5000, true);
}
os.writefile(backup, content);
ko.statusBar.AddMessage('Save '+basename+" to "+backup_fld, ‘editor’, 5000, true);