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!

Get full path from BrowseForFolder when Items.Item doesn't exist?

Status
Not open for further replies.

Stick1337

Programmer
Dec 3, 2008
8
US
First, I just decided (actually, a project decided for me) to dive into WSH and VBScript yesterday. So I don't know anything -- especially where or what to search for regarding my questions. :(

Here's what I'm trying to accomplish:

Currently, I have a .bat file that unzips some archives and puts some folders where I need them to go. That's great. (I've love to move that into a more "windows-y" script in the future.)

My problem is this: I want to create a script that does the following: Displays the BrowseForFolder dialog (w/o the New Folder button) and lets the user choose where to ultimately create a new folder (which I intend to do through script and allow the user to give the folder a name).

That almost works -- through a little searching here, I discovered the magic of objFolder.Items.Item.Path. Which words great, but throws an error when I select "Desktop" from the BFF dialog.

Is there any way around that? It's not outside the realm of possibilities for a user to want to create a folder on his desktop...

It's probably something ridiculousely obvious, but I'd greatly appreciate any help!!!
 
Post the code you are using so we can see what the problem may be.

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
Here's what I have so far:

Code:
Dim objWSH
Dim objShell
Dim objFolder
Dim objFSO

Dim strUserProfile, strBFF

'Create a WScript.Shell object and get the PROCESS environment variables
Set objWSH=WScript.CreateObject("WScript.Shell")
Set colProcEnvVars=objWSH.Environment("Process")

'Assign the user's profile (C:\Documents and Settings\{USER}\) to a string
strUserProfile=colProcEnvVars("USERPROFILE") & "\WEELs 2008\"

Set objFSO=CreateObject("Scripting.FileSystemObject")
Set objShell=CreateObject("Shell.Application")
Set objFolder=objShell.BrowseForFolder(0, "Select a parent folder for your module:", 576, 0)
If (Not objFolder Is Nothing) Then
	WScript.echo strUserProfile
	
	If (objFolder.Items.Item Is Nothing) Then
		strBFF="???"
	Else
		strBFF=objFolder.Items.Item.Path
	End If
	WScript.echo strBFF
End If

Thanks for looking!
 
Aha! (Sort of!)

Apparently, a Folder object's Self property is really a FolderItem object -- which does have a Path property.

Now things just looke like this:

Code:
...
Set objFolderItem=objFolder.Self
WScript.Echo objFolderItem.Path
...

which does indeed return "C:\Documents and Settings\%USER%\Desktop!

Sorry for the self-answered thread!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top