Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

change path from \ to /

Status
Not open for further replies.

J3WU

Programmer
May 16, 2002
6
CA
Hello,

I've built a CFileDialog class that calls an open dialog window. I then use the GetPathName() to retrieve the path of the file. Once a condition is met in another part of my program that file is executed using ShellExecute. The problem is that to open a file you use a path like this
c:/my music/mysong.mp3
But GetPathName() returns a path like this
c:\my music\mysong.mp3

Any ideas? Or someway that works better?
 
The path that "GetPathName()" returns it's the good one because windows use backslash "\" for representing paths and the normal slash "/" for internet address.So the right path is "c:\my music\mysong.mp3" not "c:/my music/mysong.mp3".
 
your probally correct, this is how i used your ShellExecute.

int CAlarmClockDlg::Ontestbutton()
{
ShellExecute (NULL,"open","C:/unzipped/demo.mp3",NULL,NULL,SW_SHOWNORMAL);
return 0;
}

And it works. Yet when i use GetPathName() on a static text it returns it with the "\" backslash.
 
The backslash is correct like Leibnitz said. You should change your function to :

int CAlarmClockDlg::Ontestbutton()
{
ShellExecute (NULL,"open","C:\\unzipped\\demo.mp3",NULL,NULL,SW_SHOWNORMAL);
return 0;
}

The double backslash represents a single backslash in c++
 
Ok, the double backslash works, but now how do i get the path of whatever the user selects to be executed by ShellExecite?

void Options::OnBUTTON3song()
{
CFileDialog m_ldFile(TRUE);

if (m_ldFile.DoModal() == IDOK)
{
m_path = m_ldFile.GetPathName();

//m_path is a static control that displays the path to user

ShellExecute (NULL,"open","m_ldFile.GetPathName()",NULL,NULL,SW_SHOWNORMAL);

UpdateData(FALSE);
}
 
Ok guys I did it!! After an hour of searching MSDN I had an idea. If I used lpstrInitialDir, part of typedef struct tagOFN, As a value for ShellExecute's default directory value. Then use GetFileName() just for the name of the file, you can open anything at any time. This is very ghetto!! I believe that there has to be a better way. Feel free to take it and use it for your own programs. Thanks for all your help! I'll probably be posting up more listings in the future.

void Options::OnBUTTON3song()
{
CFileDialog m_ldFile(TRUE);

if (m_ldFile.DoModal() == IDOK)
{
m_path = m_ldFile.GetPathName();

ShellExecute (NULL,"open",m_ldFile.GetFileName(),NULL,m_ldFile.m_ofn.lpstrInitialDir,SW_SHOWNORMAL);


UpdateData(FALSE);
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top