private void bwRun_DoWork(object sender, DoWorkEventArgs e) { DS1 ds1 = new DS1(); DS1 tmp = new DS1(); tmp.ReadXml(fp); ds1.Merge(tmp); foreach (DS1.TFolderKaitaiRow row in ds1.TFolderKaitai.Select()) { Regex rex = new Regex(row.Pat, RegexOptions.IgnoreCase | RegexOptions.Singleline); foreach (String dir in Directory.GetDirectories(row.Dir)) { if (bwRun.CancellationPending) throw new ApplicationException("キャンセルしました。"); if (rex.IsMatch(Path.GetFileName(dir))) { String fpx = Path.Combine(dir, "Thumbs.db"); if (File.Exists(fpx)) File.Delete(fpx); foreach (String fp1 in Directory.GetFiles(dir)) { if (bwRun.CancellationPending) throw new ApplicationException("キャンセルしました。"); int x = 0, cx = 1000; for (; x < cx; x++) { String suffix = (x == 0) ? "" : "~" + x; String fp2 = Path.Combine(row.Dir, Path.GetFileNameWithoutExtension(fp1) + suffix + Path.GetExtension(fp1)); if (File.Exists(fp2)) continue; File.Move(fp1, fp2); break; } } Directory.Delete(dir); } } } }
private void Form1_Load(object sender, EventArgs e) { FileInfo fi = new FileInfo(fp); if (fi.Exists && fi.Length != 0) { DS1 tmp = new DS1(); tmp.ReadXml(fp); ds1.Merge(tmp); } if (ds1.TFolderKaitai.Select().Length == 0) ds1.TFolderKaitai.AddTFolderKaitaiRow((String)null, null); foreach (DataRow dr in ds1.TFolderKaitai.Select()) { foreach (DataColumn dc in ds1.TFolderKaitai.Columns) { if (dr[dc] is DBNull) dr[dc] = dc.DefaultValue; } } ds1.AcceptChanges(); }