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);
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With