public static string GetBlockFilename(BlockDef blockItem, string filename, string outdir, string driver) { RasterIdentifyForClip rid = new RasterIdentifyForClip(filename); string exts = string.Empty; if (IsAngleFile(filename)) { exts = filename.Substring(filename.IndexOf('.')); } else { exts = GetExtByDriver(driver); } rid.RegionIdentify = blockItem.Name; string outFilename = Path.Combine(outdir, rid.ToWksFileName(exts)); if (!File.Exists(outFilename)) { return(outFilename); } else { while (File.Exists(outFilename)) { outFilename = Path.Combine(outdir, UpdateFilename(outFilename, blockItem.Name, rid)); } } return(outFilename); }
private static string UpdateFilename(string outFilename, string srcRegion, RasterIdentifyForClip rid) { string regexStr = "_" + srcRegion + @"(?<num>\d+)_"; Match m = Regex.Match(outFilename, regexStr); if (m.Success) { string num = m.Groups["num"].Value; int numtemp = int.Parse(num) + 1; string newNUM = srcRegion + numtemp; return(outFilename.Replace(srcRegion + num, newNUM)); } else { rid.RegionIdentify += "1"; return(Path.Combine(Path.GetDirectoryName(outFilename), rid.ToWksFileName(Path.GetExtension(outFilename)))); } }