Need to get directory info from parent directories


I need to get the files at a parent (or maybe its the grand parent)  directory

I am doing this in my console app:

            DirectoryInfo di = new DirectoryInfo(@"cd  ..\..\dll");
            FileInfo[] dllFiles = di.GetFiles("*.dll");

            foreach (FileInfo fi in dllFiles)

I am sure it exits if I do a cd ..\..\dll from a command line in the folder with the executable I get there

what am i doing wrong?

Thanks in advanced
Charles BaldoSoftware DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You're passing in a shell command to DirectoryInfo's constructor.

It accepts a PATH, not a command.

take the cd out.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
anarki_jimbelSenior DeveloperCommented:
No, this does not work this way.

Try my example:
        static void Main(string[] args)
            string currentDir = Directory.GetCurrentDirectory();
            DirectoryInfo diParent = new DirectoryInfo(currentDir.Substring(0, currentDir.LastIndexOf(@"\")));
            DirectoryInfo diGrandParent = diParent.Parent;
            FileInfo[] infos = diParent.GetFiles();
            Console.WriteLine("Files in Parent Dir: =============");
            for (int i = 0; i < infos.Length - 1; i++)
            Console.WriteLine("Files in GrandParent Dir: =============");
            infos = diGrandParent.GetFiles();
            for (int i = 0; i < infos.Length - 1; i++)

Open in new window

use ".." for parent
use "..\.." for grandparent

make sure you put the @, or else you need to escape the "\" because it has special meaning in strings...


@"..\..\.." is okay
"..\\..\\.." is okay

"..\.." is not.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.