Home All Groups Group Topic Archive Search About

How should I select a folder, create and select the folder?

Author
5 Jul 2005 2:43 AM
Stan Hilliard
I have a dialog in which I give users an option to select from a list
box multiple text files to save. They have the option to save
individual files or to append the text into one file.

What is a good way to allow the user to either

1) Select/return an existing folder/path to save the files in, or

2) Create a new folder for the files and return the path.

The individual file names are assigned with code so it is only the
folder that has to be chosen.

Advice will be appreciated, Stan Hilliard

Author
5 Jul 2005 4:08 AM
Larry Serflaten
Show quote Hide quote
"Stan Hilliard" <usenetreplyMS@samplingplansNOTSPAM.com> wrote
> I have a dialog in which I give users an option to select from a list
> box multiple text files to save. They have the option to save
> individual files or to append the text into one file.
>
> What is a good way to allow the user to either
>
> 1) Select/return an existing folder/path to save the files in, or
>
> 2) Create a new folder for the files and return the path.
>
> The individual file names are assigned with code so it is only the
> folder that has to be chosen.
>
> Advice will be appreciated, Stan Hilliard


Here is one method, available for systems with IE 4 or greater:

Private Sub Form_Load()
  MsgBox GetFolderName
End Sub

Private Function GetFolderName()
Dim sa, bff
   Set sa = CreateObject("Shell.Application")
   If (Not sa Is Nothing) Then
      Set bff = sa.BrowseForFolder(0, "Where do you want to save the data?", &H40, "")
      If (Not bff Is Nothing) Then
         GetFolderName = bff.ParentFolder.ParseName(bff.Title).Path
      End If
   End If
End Function


For more info see MSDN:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/objects/shell/browseforfolder.asp

Additional (advanced features) example at VBNet:
http://www.vbnet.mvps.org/code/browse/browseadv.htm

HTH
LFS
Author
15 Jul 2005 10:06 PM
Stan Hilliard
On Mon, 4 Jul 2005 23:08:22 -0500, "Larry Serflaten"
<serfla***@usinternet.com> wrote:

Show quoteHide quote
>
>"Stan Hilliard" <usenetreplyMS@samplingplansNOTSPAM.com> wrote
>> I have a dialog in which I give users an option to select from a list
>> box multiple text files to save. They have the option to save
>> individual files or to append the text into one file.
>>
>> What is a good way to allow the user to either
>>
>> 1) Select/return an existing folder/path to save the files in, or
>>
>> 2) Create a new folder for the files and return the path.
>>
>> The individual file names are assigned with code so it is only the
>> folder that has to be chosen.
>>
>> Advice will be appreciated, Stan Hilliard
>
>
>Here is one method, available for systems with IE 4 or greater:
>
>Private Sub Form_Load()
>  MsgBox GetFolderName
>End Sub
>
>Private Function GetFolderName()
>Dim sa, bff
>   Set sa = CreateObject("Shell.Application")
>   If (Not sa Is Nothing) Then
>      Set bff = sa.BrowseForFolder(0, "Where do you want to save the data?", &H40, "")
>      If (Not bff Is Nothing) Then
>         GetFolderName = bff.ParentFolder.ParseName(bff.Title).Path
>      End If
>   End If
>End Function
>
>
>For more info see MSDN:
>http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/objects/shell/browseforfolder.asp
>
>Additional (advanced features) example at VBNet:
>http://www.vbnet.mvps.org/code/browse/browseadv.htm
>
>HTH
>LFS

Thanks Larry,

I was diverted from this project for a couple weeks.

That code works good for me.

Can you suggest how to make it create a new folder below the one
selected?

For example, I can use GetFolderName to select C:\XXX\YYY\.

What is the best way to let the user add a new folder under that
selected folder: C:\XXX\YYY\ZZZ\ ?

Sincerely, Stan Hilliard
Author
16 Jul 2005 3:16 AM
Larry Serflaten
"Stan Hilliard" <usenetreplyMS@samplingplansNOTSPAM.com> wrote

> Can you suggest how to make it create a new folder below the one
> selected?

The browser is a user interface, if anyone were to make a new folder
using the browser, it would be the user. 

After the bowser  returns, you could then easily make a new folder
using the standard VB command MkDir.

>
> For example, I can use GetFolderName to select C:\XXX\YYY\.
>
> What is the best way to let the user add a new folder under that
> selected folder: C:\XXX\YYY\ZZZ\ ?

I see a New Folder button on the dialog, is it not there for you?
If the user wanted to create a new folder, they would hit the button
and then click twice (or right click for a menu) on the new folder name
to rename that folder.

LFS
Author
16 Jul 2005 7:25 PM
Stan Hilliard
On Fri, 15 Jul 2005 22:16:06 -0500, "Larry Serflaten"
<serfla***@usinternet.com> wrote:

Show quoteHide quote
>
>"Stan Hilliard" <usenetreplyMS@samplingplansNOTSPAM.com> wrote
>
>> Can you suggest how to make it create a new folder below the one
>> selected?
>
>The browser is a user interface, if anyone were to make a new folder
>using the browser, it would be the user. 
>
>After the bowser  returns, you could then easily make a new folder
>using the standard VB command MkDir.
>
>>
>> For example, I can use GetFolderName to select C:\XXX\YYY\.
>>
>> What is the best way to let the user add a new folder under that
>> selected folder: C:\XXX\YYY\ZZZ\ ?
>
>I see a New Folder button on the dialog, is it not there for you?

No. I have a directory tree that I can select a directory in. Below
that I have only two buttons: [OK] and [Cancel]

If that instance comes from the browser rather than VB, I have two
browsers installed: IE 6 SP1, and Firefox 1.0.4. I assume that IE is
the operative browser here. My OS is Win98SE.

Could it be that your IE browser version is different from mine?

>If the user wanted to create a new folder, they would hit the button
>and then click twice (or right click for a menu) on the new folder name
>to rename that folder.

I do not have the ability to rename folders in the directory tree.
They are not selectable.

The right click only gives me a "What's This?" menu.

Stan Hilliard
Author
16 Jul 2005 11:44 PM
Larry Serflaten
"Stan Hilliard" <usenetreplyMS@samplingplansNOTSPAM.com> wrote

> >I see a New Folder button on the dialog, is it not there for you?
>
> No. I have a directory tree that I can select a directory in. Below
> that I have only two buttons: [OK] and [Cancel]
>
> If that instance comes from the browser rather than VB, I have two
> browsers installed: IE 6 SP1, and Firefox 1.0.4. I assume that IE is
> the operative browser here. My OS is Win98SE.
>
> Could it be that your IE browser version is different from mine?

It certainly looks that way.   

Randy Birch has an example of the API route with options to select
advanced features.  You might try his demo to see what is or is not
going to be available on your system:

http://www.vbnet.mvps.org/code/browse/browseadv.htm

The New Folder Button apparently came with Shell32.dll Ver. 6.
I would have thought IE 6 might have upgraded Shell32, as it
appears that way from here (W2K ships Ver 5, but I've got Ver 6
installed from somewhere...)  Perhaps it won't be available on
Win9x?...

For more version info, check here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/programmersguide/versions.asp

LFS
Author
25 Jul 2005 6:59 PM
Stan Hilliard
On Sat, 16 Jul 2005 18:44:59 -0500, "Larry Serflaten"
<serfla***@usinternet.com> wrote:

Show quoteHide quote
>
>"Stan Hilliard" <usenetreplyMS@samplingplansNOTSPAM.com> wrote
>
>> >I see a New Folder button on the dialog, is it not there for you?
>>
>> No. I have a directory tree that I can select a directory in. Below
>> that I have only two buttons: [OK] and [Cancel]
>>
>> If that instance comes from the browser rather than VB, I have two
>> browsers installed: IE 6 SP1, and Firefox 1.0.4. I assume that IE is
>> the operative browser here. My OS is Win98SE.
>>
>> Could it be that your IE browser version is different from mine?
>
>It certainly looks that way.   
>
>Randy Birch has an example of the API route with options to select
>advanced features.  You might try his demo to see what is or is not
>going to be available on your system:
>
>http://www.vbnet.mvps.org/code/browse/browseadv.htm
>
>The New Folder Button apparently came with Shell32.dll Ver. 6.
>I would have thought IE 6 might have upgraded Shell32, as it
>appears that way from here (W2K ships Ver 5, but I've got Ver 6
>installed from somewhere...)  Perhaps it won't be available on
>Win9x?...
>
>For more version info, check here:
>http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/programmersguide/versions.asp
>
>LFS

Thanks Larry,

I used your original GetFolderName() example and MkDir to make a new
sub folder.

I have run it on Win98SE and Win XP. The method is sufficient on Win98
but is better on XP with its own new folder button.