private void tbUserDefinition_TextChanged(object sender, EventArgs eventArgs) { string tmp_path = @"c:\" + "sample.txt"; string result = BackupArgs.UserDefinedBackupFileName(tmp_path, tbUserDefinition.Text); result = result.Replace(@"c:\", ""); lbUserDefinitionSampleResult.Text = result; }
void BackupFiles(ListViewItem item) { try { string sourcePath = item.SubItems[FileListView.ClmnPathNumber].Text; string destPath = BackupArgs.UserDefinedBackupFileName(sourcePath, BackupArgs.TextAsUserDefined()); string destDir = Path.GetDirectoryName(destPath); if (!Directory.Exists(destDir)) { Directory.CreateDirectory(destDir); } if (BackupArgs.AppendMode) { int codepg = JpnEncoding.NameToJpnEncoding(item.SubItems[1].Text).Encoding.CodePage; Encoding enc = null; if (codepg == 65001) { // avoid Encoding.GetEncoding(65001) as it refers to UTF-8 with BOM enc = new UTF8Encoding(false); } else { enc = Encoding.GetEncoding(codepg); } string text; using (FileStream fs = new FileStream(sourcePath, FileMode.Open, FileAccess.Read)) { using (StreamReader sr = new StreamReader(fs, enc)) { text = sr.ReadToEnd(); } DateTime dtNow = DateTime.Now; string eol = Environment.NewLine; string borderline = new string('-', sourcePath.Length > 20 ? sourcePath.Length : 20); // 20 is length of date string text = borderline + eol + text; text = sourcePath + eol + text; text = dtNow.ToString("yyyy-MM-dd HH:mm:ss") + eol + text; text = borderline + eol + text; text = eol + text + eol; } using (FileStream fs = new FileStream(destPath, FileMode.Append, FileAccess.Write)) { using (StreamWriter sw = new StreamWriter(fs, enc)) { sw.Write(text); } } } else { File.Copy(sourcePath, destPath, true); } } catch (OperationCanceledException) { throw; } catch (Exception exception) { Progress.ReportError(exception, "バックアップエラー: "); } }