通过浏览按钮获取文件夹路径

时间:2012-10-09 15:16:10

标签: c++ file filepath

点击浏览按钮后,浏览文件夹并选择文件,即可获得完整的文件路径

但我希望通过浏览路径到

我为文件路径

执行了以下操作
                 Stream^ myStream;  
                 OpenFileDialog^ openFileDialog1 = gcnew OpenFileDialog;

                 openFileDialog1->InitialDirectory = "c:\\";
                 //openFileDialog1->Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
                 openFileDialog1->FilterIndex = 2;
                 openFileDialog1->RestoreDirectory = true;

                 if ( openFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK )
                 {
                     if ( (myStream = openFileDialog1->OpenFile()) != nullptr )
                     {                               

                         String^ p1 = openFileDialog1->FileName; 


                         MessageBox ::Show (p1);

                         myStream->Close();
                     }

1 个答案:

答案 0 :(得分:1)

要获取文件夹路径而不是文件名,请使用FolderBrowserDialog