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!

cfiledialog location folders

Status
Not open for further replies.

jl3574

Programmer
Jun 5, 2003
76
CA
i'm creating a CFileDialog to ask user to select a file
however i want the user to locate a folder only and not just a speicific file.

FILE *filename;
CString cs;
//open file
CFileDialog m_ldFile(TRUE);
if(m_ldFile.DoModal()==IDOK)
cs=m_ldFile.GetFileName();
filename = fopen(cs,"r");
UpdateData(FALSE);

//this retrives the file and puts it in the file pointer
is there a way i can just get the folder name from the selected folder from the user?
 
You can get the whole path and parse out the folder name.

-pete
 
If you get the pathname using GetPathName()

You can then use the C function strtok(pathname,"\\").

put the above funtion in a while loop and this will split the file name into all required components.

example:

CString CSIMAppDlg::GetFileName(CString strPathname)
{
char seps[] = "\\";
char *token;
char *prev;
char work[256];
int len;
strcpy(work, strPathname);

token = strtok(work, seps );
while( token != NULL )
{
prev = token;
token = strtok( NULL, seps );
}

len = prev - work;

return strPathname.Left(len);

}

 
Perhaps you're after the SHBrowseForFolder function.

/Per
[sub]Nerdy signatures are as lame as the inconsistent stardates of STTNG.[/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top