?
Solved

parsing string vc++

Posted on 2009-05-14
8
Medium Priority
?
263 Views
Last Modified: 2013-12-14
I have strig with filename from openFileDialog. I want to extract folder path out of it. Something like
c:\project\folder\filename
and i want to get
c:\project\folder
what is a good way of going this? I am using VS2008 and windows forms appl.
0
Comment
Question by:funcoding
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 8

Expert Comment

by:RyanAndres
ID: 24387425
Is this for C++ or C#?
0
 
LVL 1

Author Comment

by:funcoding
ID: 24387449
vc++
0
 
LVL 8

Expert Comment

by:RyanAndres
ID: 24387479
Not sure what's the syntax for VC++ but here's how you do it with C#.
This shoud help you since the classes are the same.
OpenFileDialog ofd = new OpenFileDialog();
ofd.ShowDialog();
string filename = ofd.FileName;
string path = Path.GetDirectoryName(ofd.FileName);

Open in new window

0
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 
LVL 1

Author Comment

by:funcoding
ID: 24387567
what is Path in there? "Path.GetDirectoryName"
0
 
LVL 8

Accepted Solution

by:
RyanAndres earned 500 total points
ID: 24387697
System.IO.Path
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 24387993
try

 
private:
    FileStream* OpenFile() {
        // Displays an OpenFileDialog and shows the read/only files.
 
        OpenFileDialog* dlgOpenFile = new OpenFileDialog();
        dlgOpenFile->ShowReadOnly = true;
 
        if (dlgOpenFile->ShowDialog() == DialogResult::OK) {
           String* path = dlgOpenFile->FileName;
           String* folder = path->Substring(0, path->LastIndexOfAny(L"\\/"));
           ...
        }
        return 0;
    }

Open in new window

0
 
LVL 9

Expert Comment

by:tculler
ID: 24390439
You can't use pointers with Managed types; instead, Microsoft has provided us with yet another indirection operator indicating a handle to a managed type, which is "^". To make the above code work, do the following:

First, change all asterisks (*) to ^.

Second, change "new" OpenFileDialog to "gcnew"

Hope I helped,
Nate
0
 
LVL 1

Author Comment

by:funcoding
ID: 24391570
I completely forgot to update that RyanAdnre's suggestion had worked. Thanks everyone else for input also.

String^ filename = openFileDialog->filename;
String^ folderpath = System::IO::Path::GetDirectoryName(filename);
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
Suggested Courses

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question