FolderBrowserDialog last Folder Name

1.3k views Asked by At

I'm new to C++/CLI and have a Question about the FolderBrowserDialog function.

Using ->SelectedPath gives me "C:\Folder\Subfolder\Selected Folder"

How can I save JUST "Selected Folder" to a string?

FolderBrowserDialog^ DestinationFolderDialog;
    DestinationFolderDialog = gcnew System::Windows::Forms::FolderBrowserDialog;

    System::Windows::Forms::DialogResult result = DestinationFolderDialog->ShowDialog();
    if (result == System::Windows::Forms::DialogResult::OK)
    {
        String^ path = DestinationFolderDialog->SelectedPath;
        SetDestinationPath(path);
        lblDestinationPath->Text = path;

    }

The way I set my Destination Path

And now I want to work with it

String^ pathSource = GetSourcePath();
String^ pathDest = GetDestinationPath();

Im trying to generate Symlinks.
So im Selecting "Y:\Movies\Movie_a" as Source
And im Selecting "X:\" as Destination for my Symlink Folder

To Create it I need to add "Movie_a" to "X:\"

Can someone help me?

1

There are 1 answers

5
Dusteh On BEST ANSWER

If what you want is to extract the last dir name from C:\Folder\Subfolder\Selected Folder then you can:

  • use Path.GetFileName method to acquire the last part from the path
  • call String.Split with the Path.PathSeparator and take the last array element

Updated in respect to @LucasTrzesniewski comment