我希望能够搜索文件夹和子文件夹名称,然后如果它们的名称具有特定模式,请更改或从文件夹名称中删除它们。我使用了下面的代码但folderNameList返回{}string[] dirs = Directory.GetDirectories(myRootPath, "*", SearchOption.AllDirectories);string findFolderNamePattern = @"((?i)mydomain.com|sitename(?-i))";string replacement = " ";Match folderNameList = Regex.Match(dirs.ToString(), findFolderNamePattern); foreach (var folder in folderNameList.ToString()) { folder = Regex.Replace(folder.ToString(), replacement); }你也可以在这里看到正则表达式
1 回答
翻翻过去那场雪
TA贡献2065条经验 获得超14个赞
您需要做的就是:
string[] directories = Directory.GetDirectories(myRootPath, "*", SearchOption.AllDirectories);
string findFolderNamePattern = @"((?i)mydomain.com|sitename(?-i))";
string replacement = " ";
foreach (var directory in directories)
{
var newFolder = Regex.Replace(directory, findFolderNamePattern, replacement);
}
- 1 回答
- 0 关注
- 167 浏览
添加回答
举报
0/150
提交
取消