Need to get directory info from parent directories

Hi

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)
            {
                Console.WriteLine(fi);
            }

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
chuck
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.

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

It accepts a PATH, not a command.

take the cd out.

-john
0

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_jimbelCommented:
No, this does not work this way.

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

Open in new window

0
jgordosCommented:
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...

so,

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

This:
"..\.." is not.

-john
0
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
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.