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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Returning folder path from Common Dialog

Status
Not open for further replies.

felicitea

Programmer
Jun 13, 2002
9
US
If a user selects an empty folder in the File Open common dialog, is there any way to get the path of that folder? I can get it from the filename property of the common dialog if there is a file, but if the filename property is "", I can't seem to get the path of the folder. Thanks.
 

set the filename property prior to call the showopen method.

As long as the user does not delete your filename that you have provided you will get the path.

Oh! yeah do not set the cdlOFNFileMustExist flag or this will not work either.
 
Ok, so now I have a path to this empty folder, and I want to delete the folder. Since it's the current directory, RmDir doesn't work. I've tried using ChDir to change the current directory, but it doesn't do anything. Any ideas how I can change the current directory so I can delete the empty directory the user has selected? Thanks. Code is as follows:

strFiles = frmWizard.CommonDialog1.FileName
If Dir(strFiles) = "" Then
strPath = left(strFiles, Len(strFiles)- Len(frmWizard.CommonDialog1.FileTitle))
'User selected folder instead of file.
intAns = MsgBox("You have selected a folder. Would you like to delete it?", vbYesNo, "No Files Found")
If intAns = vbYes Then
ChDir App.Path
RmDir (strPath)
Else
Exit Sub
End If
End If
 
In DOS 'CHDIR ..' (thats just 2 full stops) works to move up one level in the directory structure, so I guess it still will. You should then be able to remove the subdirectory Let me know if this helps
________________________________________________________________
If you are worried about how to post, please check out FAQ222-2244 first

'There are 10 kinds of people in the world: those who understand binary, and those who don't.'
 
Yes! By stripping the name of the empty directory off the path and using the resulting string as the target, I was able to set the current dirctory to the next level up. After that I could delete the empty directory. The 'ChDir..' syntax doesn't work though. (If I understand you correctly that that is what you were suggesting I try.) Thanks for your help, John! [bigsmile]
 
Glad to have helped. In VB you would need to use CHDIR ".." so the .. becomes a string Let me know if this helps
________________________________________________________________
If you are worried about how to post, please check out FAQ222-2244 first

'There are 10 kinds of people in the world: those who understand binary, and those who don't.'
 
Thanks again. I thought I'd tried ChDir "..", but I guess I just tried other possibilities and hallucinated that one!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top