Link to home
Start Free TrialLog in
Avatar of scm0sml
scm0sml

asked on

Getting the last directory from a directory path

I'm using a folder browser to get a path to a directory that I will be compressing.

For eg C:\\Program File\Visual Studio.

As well as this I want to read the last directory of the path into a string...so in this case Visual Studio as this will be the name of the compressed file.

The code I have to get the path is:
//set source path of snapshot
snapshotSource = _snapshotFolderBrowser.SelectedPath;

//now I need the code for
string compressedFileName = ???

Can someone give me some pointers to go about this please....

Cheers



ASKER CERTIFIED SOLUTION
Avatar of Alexandre Simões
Alexandre Simões
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This may prevent errors:

            System.IO.DirectoryInfo pDirInfo = new System.IO.DirectoryInfo("path");
            System.IO.DirectoryInfo lastDirInfo =
                (pDirInfo.GetDirectories()==null || pDirInfo.GetDirectories().Length==0) ? null : pDirInfo.GetDirectories()[pDirInfo.GetDirectories().Length - 1];


Alex :p
Avatar of scm0sml
scm0sml

ASKER

yep working...

cheers for that!