Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"'System.IO.FileSystemInfo.FullPath' is inaccessible due to its protection level" error in C#

Tags:

c#

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);
        }
    }
}
like image 369
cethint Avatar asked Mar 07 '12 22:03

cethint


1 Answers

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);
        }
    }
}
like image 96
Darin Dimitrov Avatar answered Sep 27 '22 03:09

Darin Dimitrov