我有一些看起来像这样的文件:
prtx010.prtx010.0199.785884.351.05042413
prtx010.prtx010.0199.123456.351.05042413
prtx010.prtx010.0199.122566.351.05042413
prtx010.prtx010.0199.this.351.05042413
prtx010.prtx010.0199.something.351.05042413
现在,我想对这些文件进行子串化,以便得到以下结果
785884
123456
122566
(这是左21右-12)
问题是,我只想在指定位置之间对这些文件进行子串化,前提是它们是数字且长度为 6 位。
任何关于如何实现这一目标的想法都非常感激。
目前,这就是我所拥有的,但它对所有文件进行了子串化:
//Rename all files
DirectoryInfo di = new DirectoryInfo(@"\\prod\abc"); //location of files
DirectoryInfo di2 = new DirectoryInfo(@"\\prod\abc\");//where they are going
string lstrSearchPattern = "prtx010.prtx010.0199.";
foreach (FileInfo fi in di.GetFiles(lstrSearchPattern + "*"))
{
string newName = fi.Name.Substring(lstrSearchPattern.Length, 6);
fi.MoveTo(di2 + newName);
//do something with the results
}
di = null;