我有一个类似如下的C#程序。但它失败了。错误是'System.IO.FileSystemInfo.FullPath‘由于其保护级别而无法访问。FullPath用蓝色下划线。
protected void Main(string[] args)
{
DirectoryInfo parent = new DirectoryInfo(@"C:\Users\dell\Desktop\rename");
foreach (DirectoryInfo child in parent.GetDirectories())
{
string newName = child.FullPath.Replace('_', '-');
if (newName != child.FullPath)
{
child.MoveTo(newName);
}
}
}发布于 2012-03-08 06:59:28
您要查找的属性名为FullName,而不是FullPath
static void Main()
{
DirectoryInfo parent = new DirectoryInfo(@"C:\Users\dell\Desktop\rename");
foreach (DirectoryInfo child in parent.GetDirectories())
{
string newName = child.FullName.Replace('_', '-');
if (newName != child.FullName)
{
child.MoveTo(newName);
}
}
}发布于 2012-03-08 07:02:10
尝试使用FullName而不是FullPath:
http://msdn.microsoft.com/fr-fr/library/8s2fzb02.aspx
这对您来说应该是可行的:)
https://stackoverflow.com/questions/9610325
复制相似问题