/// <summary> /// zip this file into archive /// </summary> /// <returns>the archive name</returns> public RaiFile Zip() { var inFolder = new RaiFile(this.FullName); var file = new RaiFile(this.FullName); inFolder.Name = file.Name; inFolder.Path = inFolder.Path + inFolder.Name; inFolder.mv(file); file.Ext = file.Ext + ".zip"; File.Delete(file.FullName); // delete any pre-existing file try { ZipFile.CreateFromDirectory(inFolder.Path, file.FullName); //ZipFile. } catch (Exception) { return(null); } return(file); }
/// <summary>create a backup file</summary> /// <param name="copy">moves if false, copies otherwise</param> /// <returns>name of backupfile, if there was one created</returns> /// <remarks>the Os.LocalBackupDir will be used; make sure it's not in the Dropbox</remarks> public string backup(bool copy = false) { if (!File.Exists(FullName)) { return(null); // no file no backup } var backupFile = new RaiFile(FullName); var idx = (backupFile.Path.Length > 2 && backupFile.Path[1] == ':') ? 3 : 0; // works as expected for c:/123 or c:\123, but not for c:123 var s = backupFile.Path.Substring(idx); backupFile.Path = (Os.LocalBackupDir + s).Replace("Dropbox/", "").Replace("dropbox/", ""); // eliminates Dropbox for LocalBackupDir to avoid ensure mkdir(backupFile.Path); backupFile.Name = backupFile.Name + " " + DateTimeOffset.UtcNow.ToString(Os.DATEFORMAT); backupFile.Ext = Ext; if (copy) { backupFile.cp(this); } else { backupFile.mv(this); } return(backupFile.FullName); }