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!

Common Dialog box

Status
Not open for further replies.

99mel

Programmer
Oct 18, 1999
379
GB
I am wanting to get a directory name and not a filename in vb6 using something like a common dialog box (save/as, open).&nbsp;&nbsp;I'm currently using a Save/As Common dialog box but u need to give the file name.&nbsp;&nbsp;Is there any properties to this one that allows the user to just give the directory name.&nbsp;&nbsp;Or is there anyother components to add??<br><br>I've seen before like a dialog box where u just pick the directory u want.<br><br>Thanks for any help!!
 
Can't you the Dir box control for this.&nbsp;&nbsp;You can use the Drive box, in conjunction with the directory box control to choose drives and directories.&nbsp;&nbsp;Then use the .value property of the directory box to get the directory chosen.
 
here is something to work with.<br>put this in a module<br>-------------------------------------<br>Option Explicit<br><br>Const FO_MOVE As Long = &H1<br>Const FO_COPY As Long = &H2<br>Const FO_DELETE As Long = &H3<br>Const FO_RENAME As Long = &H4<br><br>Const FOF_MULTIDESTFILES As Long = &H1<br>Const FOF_CONFIRMMOUSE As Long = &H2<br>Const FOF_SILENT As Long = &H4<br>Const FOF_RENAMEONCOLLISION As Long = &H8<br>Const FOF_NOCONFIRMATION As Long = &H10<br>Const FOF_WANTMAPPINGHANDLE As Long = &H20<br>Const FOF_CREATEPROGRESSDLG As Long = &H0<br>Const FOF_ALLOWUNDO As Long = &H40<br>Const FOF_FILESONLY As Long = &H80<br>Const FOF_SIMPLEPROGRESS As Long = &H100<br>Const FOF_NOCONFIRMMKDIR As Long = &H200<br><br>Type SHFILEOPSTRUCT<br>&nbsp;&nbsp;&nbsp;&nbsp;hWnd As Long<br>&nbsp;&nbsp;&nbsp;&nbsp;wFunc As Long<br>&nbsp;&nbsp;&nbsp;&nbsp;pFrom As String<br>&nbsp;&nbsp;&nbsp;&nbsp;pTo As String<br>&nbsp;&nbsp;&nbsp;&nbsp;fFlags As Long<br>&nbsp;&nbsp;&nbsp;&nbsp;fAnyOperationsAborted As Long<br>&nbsp;&nbsp;&nbsp;&nbsp;hNameMappings As Long<br>&nbsp;&nbsp;&nbsp;&nbsp;lpszProgressTitle As String<br>End Type<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>Declare Function SHFileOperation Lib &quot;Shell32.dll&quot; _<br>&nbsp;&nbsp;&nbsp;&nbsp;Alias &quot;SHFileOperationA&quot; (lpFileOp As SHFILEOPSTRUCT) As Long<br><br>&nbsp;Const BIF_RETURNONLYFSDIRS = 1<br>&nbsp;Const BIF_DONTGOBELOWDOMAIN = 2<br>&nbsp;Const MAX_PATH = 260<br><br>Type BrowseInfo<br>&nbsp;&nbsp;&nbsp;&nbsp;hWndOwner As Long<br>&nbsp;&nbsp;&nbsp;&nbsp;pIDLRoot As Long<br>&nbsp;&nbsp;&nbsp;&nbsp;pszDisplayName As Long<br>&nbsp;&nbsp;&nbsp;&nbsp;lpszTitle As Long<br>&nbsp;&nbsp;&nbsp;&nbsp;ulFlags As Long<br>&nbsp;&nbsp;&nbsp;&nbsp;lpfnCallback As Long<br>&nbsp;&nbsp;&nbsp;&nbsp;lParam As Long<br>&nbsp;&nbsp;&nbsp;&nbsp;iImage As Long<br>End Type<br><br><br>Declare Function SHBrowseForFolder Lib &quot;shell32&quot; _<br>&nbsp;&nbsp;&nbsp;&nbsp;(lpbi As BrowseInfo) As Long<br>Declare Function SHGetPathFromIDList Lib &quot;shell32&quot; _<br>&nbsp;&nbsp;&nbsp;&nbsp;(ByVal pidList As Long, _<br>&nbsp;&nbsp;&nbsp;&nbsp;ByVal lpBuffer As String) As Long<br>Declare Function lstrcat Lib &quot;kernel32&quot; Alias &quot;lstrcatA&quot; _<br>&nbsp;&nbsp;&nbsp;&nbsp;(ByVal lpString1 As String, ByVal _<br>&nbsp;&nbsp;&nbsp;&nbsp;lpString2 As String) As Long<br><br><br>Public Function SFODelete(f As Form, sFiles As String, _<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bRecycle As Boolean) As Boolean<br>'This function uses the SHFileOperation API function to delete a list<br>'of files.&nbsp;&nbsp;The files can be deleted to the Recycle Bin or deleted<br>'straight off the disk.<br>'Parameters: f - A reference to the form calling the function.<br>'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sFiles - A NULL separated list of files to be deleted.<br>'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bRecycle - True to move files to the Recycle Bin,<br>'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;False to delete files directly.<br>'Returns: True on success, False on failure<br><br>&nbsp;&nbsp;&nbsp;&nbsp;Dim DelFileOp As SHFILEOPSTRUCT<br>&nbsp;&nbsp;&nbsp;&nbsp;Dim lRet As Long<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;With DelFileOp<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.hWnd = f.hWnd<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.wFunc = FO_DELETE<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.pFrom = sFiles<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'If the Recycle flag is set, send the deleted files<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'to the Recycle Bin.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;If bRecycle Then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.fFlags = FOF_ALLOWUNDO<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;End If<br>&nbsp;&nbsp;&nbsp;&nbsp;End With<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'Call the API function.<br>&nbsp;&nbsp;&nbsp;&nbsp;lRet = SHFileOperation(DelFileOp)<br>&nbsp;&nbsp;&nbsp;&nbsp;SFODelete = True&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'Assume operation suceeded<br>&nbsp;&nbsp;&nbsp;&nbsp;If lRet &lt;&gt; 0 Then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SFODelete = False&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'The entire operation failed<br>&nbsp;&nbsp;&nbsp;&nbsp;Else<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'One or more individual deletions failed.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;If DelFileOp.fAnyOperationsAborted &lt;&gt; 0 Then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SFODelete = False<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;End If<br>&nbsp;&nbsp;&nbsp;&nbsp;End If<br>End Function<br><br><br>Public Function SFOCopyMove(f As Form, sFiles As String, _<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bCMFlag As Boolean, sDir As String) As Boolean<br>'This function uses the SHFileOperation API function to move or copy<br>'a list of files to a destination directory.&nbsp;&nbsp;The files in the list do<br>'not have to be in the same directory.<br>'Parameters: f - A reference to the form calling the function.<br>'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sFiles - A NULL separated list of files (including full<br>'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;path names).<br>'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bCMFlag - True to perform Copy, False to perform Move.<br>'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sDir - String containing the destination path.<br>'Returns: True on success, False on failure<br><br>&nbsp;&nbsp;&nbsp;&nbsp;Dim lRet As Long<br>&nbsp;&nbsp;&nbsp;&nbsp;Dim fileop As SHFILEOPSTRUCT<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;With fileop<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.hWnd = f.hWnd<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'If the bCMFlag is True, we're going to do a COPY, else<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'we're going to do a MOVE.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;If bCMFlag Then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.wFunc = FO_COPY<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Else<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.wFunc = FO_MOVE<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;End If<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.pFrom = sFiles<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.pTo = sDir<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.fFlags = FOF_FILESONLY<br>&nbsp;&nbsp;&nbsp;&nbsp;End With<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'Call the API function.<br>&nbsp;&nbsp;&nbsp;&nbsp;lRet = SHFileOperation(fileop)<br>&nbsp;&nbsp;&nbsp;&nbsp;SFOCopyMove = True&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'Assume move suceeded.<br>&nbsp;&nbsp;&nbsp;&nbsp;If lRet &lt;&gt; 0 Then&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'The entire operation failed.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SFOCopyMove = False<br>&nbsp;&nbsp;&nbsp;&nbsp;Else<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'One or more individual moves or copies failed.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;If fileop.fAnyOperationsAborted &lt;&gt; 0 Then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SFOCopyMove = False<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;End If<br>&nbsp;&nbsp;&nbsp;&nbsp;End If<br>End Function<br>-----------------------------------------------------<br>then this in an event<br>Dim lpIDList As Long<br>&nbsp;&nbsp;&nbsp;&nbsp;Dim sBuffer As String<br>&nbsp;&nbsp;&nbsp;&nbsp;Dim szTitle As String<br>&nbsp;&nbsp;&nbsp;&nbsp;Dim tBrowseInfo As BrowseInfo<br>&nbsp;&nbsp;&nbsp;&nbsp;szTitle = &quot;This is the title&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;With tBrowseInfo<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.hWndOwner = Me.hWnd<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.lpszTitle = lstrcat(szTitle, &quot;&quot;)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.ulFlags = BIF_RETURNONLYFSDIRS + BIF_DONTGOBELOWDOMAIN<br>&nbsp;&nbsp;&nbsp;&nbsp;End With<br>&nbsp;&nbsp;&nbsp;&nbsp;lpIDList = SHBrowseForFolder(tBrowseInfo)<br>&nbsp;&nbsp;&nbsp;&nbsp;If (lpIDList) Then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sBuffer = Space(MAX_PATH)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SHGetPathFromIDList lpIDList, sBuffer<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sBuffer = Left(sBuffer, InStr(sBuffer, vbNullChar) - 1)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;msgbox sBuffer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top