I have a C# programme like as follows. But it fails. Error is 'System.IO.FileSystemInfo.FullPath' is inaccessible due to its protection level. And FullPath underlined in blue.
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);
}
}
}
The property that you are looking for is called FullName
, not 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);
}
}
}
Try FullName instead of FullPath:
http://msdn.microsoft.com/fr-fr/library/8s2fzb02.aspx
this should work for you :)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.