date manipulation in AIR
I have:
targetFile = air.File.desktopDirectory.resolvePath('myFolder' + files[f].name);
files[f].moveTo(targetFile,true); // Overwrite开发者_如何学C
I would like to make a backup copy of targetFile before overwriting it.
Maybe something with datetime stamp so that I have infinite backups, which of course would get cleared out periodically (read: once every blue moon).
(function() {
Date.prototype.toYMD = Date_toYMD;
function Date_toYMD() {
var year, month, day;
year = String(this.getFullYear());
month = String(this.getMonth() + 1);
if (month.length == 1) {
month = "0" + month;
}
day = String(this.getDate());
if (day.length == 1) {
day = "0" + day;
}
return '' + year + month + day;
}
})();
(function() {
Date.prototype.toHMS = Date_toHMS;
function Date_toHMS() {
var hour, minute, second;
hour = String(this.getHours());
minute = String(this.getMinutes());
second = String(this.getSeconds());
return '' + hour + minute + second;
}
})();
and then
var dt = new Date();
var ArcBakFile = air.File.desktopDirectory.resolvePath('myDir/myFile.' + dt.toYMD() + '.' + dt.toHMS() + '.txt');
精彩评论