Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


select directory box

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,2190
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> select directory box
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1] 2   next >   >>
Login
Message << Older Topic   Newer Topic >>
 select directory box - 2/28/2005 12:25:25 AM   
  wetarded1

 

Posts: 17
Score: 0
Joined: 2/17/2005
From:
Status: offline

Hi all,
I had a quick question. I am trying to create a box that is similar to a 'save as' box, where a user can select a directory to install files. Any suggestions would be greatly appreciate. Thanks




 
 
Post #: 1
 
 Re: select directory box - 2/28/2005 12:47:44 AM   
  Zifter


Posts: 318
Score: 0
Joined: 1/5/2005
From: Belgium
Status: offline
You need at least Windows XP for the following scripts:
      

      
HTH

(in reply to wetarded1)
 
 
Post #: 2
 
 Re: select directory box - 2/28/2005 3:55:55 AM   
  token

 

Posts: 1917
Score: 0
Joined: 1/14/2005
From:
Status: offline
Zifter, interesting post :)

(in reply to wetarded1)
 
 
Post #: 3
 
 Re: select directory box - 2/28/2005 5:35:57 AM   
  wetarded1

 

Posts: 17
Score: 0
Joined: 2/17/2005
From:
Status: offline
zifter. Do you know of one that will allow the user to select a directory instead of a file?

(in reply to wetarded1)
 
 
Post #: 4
 
 Re: select directory box - 2/28/2005 7:02:56 AM   
  mbouchard


Posts: 1916
Score: 16
Joined: 5/15/2003
From: USA
Status: offline
Wetarded1,

Are you looking for something like this? I did not write this but came across it a while ago and it is commented pretty well.


      

(in reply to wetarded1)
 
 
Post #: 5
 
 Re: select directory box - 2/28/2005 10:16:58 AM   
  beaker

 

Posts: 78
Score: 0
Joined: 1/27/2005
From: USA
Status: offline
As a follow-on to mbouchard's post, the 'BrowseForFolder' method of the Shell.Application object takes as its third parameter a bitwise combination of various flags to control the features of the dialog box. In his example, the default value of '0' is used. Here are all of the possible values for the third parameter:

      
Here is an example of combining more than one flag together to show the optional edit box and to show files as well as folders:

Set oFolder = oShell.BrowseForFolder (0, "Select Folder", _
(BIF_BROWSEINCLUDEFILES Or BIF_EDITBOX))

(in reply to wetarded1)
 
 
Post #: 6
 
 Re: select directory box - 3/1/2005 1:03:18 AM   
  wetarded1

 

Posts: 17
Score: 0
Joined: 2/17/2005
From:
Status: offline
you guys are awesome. You hit the nail right on the head. Exactly what I was looking for.

Thank you very much

(in reply to wetarded1)
 
 
Post #: 7
 
 Re: select directory box - 3/1/2005 3:09:47 AM   
  wetarded1

 

Posts: 17
Score: 0
Joined: 2/17/2005
From:
Status: offline
do you guys have an idea on how to implement that? I tried placing it in to a script I have already written with a function statement at the beginning and an end statement, but I run into a problem with the recursion of if it. I am fairly new to vbscript and not really sure what is going. If I run the script by itself, it works fine, but if I put it into a function it wont work.

(in reply to wetarded1)
 
 
Post #: 8
 
 Re: select directory box - 3/1/2005 4:03:23 AM   
  beaker

 

Posts: 78
Score: 0
Joined: 1/27/2005
From: USA
Status: offline
Step by step, without recopying the whole thing, so that you can learn:
1. Place, 'Function BrowseForFolder' at the top.
2. Place, 'End Function' at the end.
3. Replace both lines 'msgbox "Path of chosen folder:" & vbcrlf & spath' with
line 'BrowseForFolder = "Path of chosen folder:" & vbcrlf & sn'.
4. Call the function with 'MsgBox BrowseForFolder' to see the return value.

That should do it.

(in reply to wetarded1)
 
 
Post #: 9
 
 Re: select directory box - 3/1/2005 4:23:08 AM   
  wetarded1

 

Posts: 17
Score: 0
Joined: 2/17/2005
From:
Status: offline
That isnt the problem. I can call the function just fine. The problem lies in the function itself. If I select a folder that does not have a subfolder, the recursion does not find the path of the folder. I cant really read what is going on with it because I dont have much experience reading the code and debugging. I have tried placing msgbox's through out the code to see where it fails, and it seems to fail as soon as it checks the folder and finds no subfolder/files and tries to get the path.

(in reply to wetarded1)
 
 
Post #: 10
 
 Re: select directory box - 3/1/2005 5:32:28 AM   
  beaker

 

Posts: 78
Score: 0
Joined: 1/27/2005
From: USA
Status: offline
I just wrote this. Please try it and see if it is better:

      
If that works for you, we can set about customizing it specifically for your application.

(in reply to wetarded1)
 
 
Post #: 11
 
 Re: select directory box - 3/1/2005 5:45:44 AM   
  wetarded1

 

Posts: 17
Score: 0
Joined: 2/17/2005
From:
Status: offline
beaker. I figured out what it was that was causing a problem. I had Option Explicit in there and it wouldnt allow it to find the directory. I took that out and it works great now. Thanks for all your help on this. I really appreciate it.

(in reply to wetarded1)
 
 
Post #: 12
 
 Re: select directory box - 3/1/2005 5:54:15 AM   
  beaker

 

Posts: 78
Score: 0
Joined: 1/27/2005
From: USA
Status: offline
I actually got some buggy behavior, too, when I tried mbouchard's (found) version. When I would navigate to a folder on my desktop, it would append the first three letters of the first filename onto the path for the folder. When I tried to fix that, it broke other situations. Also, if the use of 'Option Explicit' determines whether or not it works, it probably is not written correctly. I like my new version better.

By the way, you do not see too much use of this 'folder browser' dialog box, but coincidentally today I noticed that Windows Media Player uses it to help the user navigate to a folder containing media files. So even the big boys still use this method!

(in reply to wetarded1)
 
 
Post #: 13
 
 Re: select directory box - 3/1/2005 5:57:09 AM   
  wetarded1

 

Posts: 17
Score: 0
Joined: 2/17/2005
From:
Status: offline
it did have really odd behavior with option explicit.
what does that mean? I am still trying to learn this stuff as I go.
but it works now, I am going to try the code that you wrote. I might implement that code because it is shorter and nicer on the eyes.

(in reply to wetarded1)
 
 
Post #: 14
 
 Re: select directory box - 3/1/2005 6:53:59 AM   
  beaker

 

Posts: 78
Score: 0
Joined: 1/27/2005
From: USA
Status: offline
'Option Explicit' means that you must explicitly declare all variables before use. As you may or may not know, VBS is flexible on this point. If you do not use 'Option Explicit', you can create and start using variables without previously reserving memory for them with the Dim, Public, or Private statements. As an overall programming practice, most people recommend the use of Option Explicit because it prevents a typographical error from inadvertantly creating a new variable when you thought the variable already existed. I also recommend its use. My earlier statement from a couple of posts ago was dumb. What must have happened is that the original author did indeed create a variable somewhere in the procedure that he did not declare at the top. When you put 'Option Explicit' in there, it exposed that fact, which then became a problem. It usually causes a runtime error when the program attempts to use the undeclared variable. By the way, you only use the 'Option Explicit' statement one time in a module, and it is placed at the top of the module.

(in reply to wetarded1)
 
 
Post #: 15
 
 Re: select directory box - 6/9/2005 9:36:04 PM   
  kya_karey

 

Posts: 39
Score: 0
Joined: 5/11/2005
From: India
Status: offline
what should i do if i need to search some perticular file ??

For to search all vbs file this is good

objDialog.Filter = "VBScript Scripts|*.vbs|All Files|*.*"

But when i want some file like vbs file whose names start with "A"

i am writing as follow

objDialog.Filter = "VBScript Scripts|*.vbs|All Files|*A.*"

But its not working can anybody tell me what i have to do

and also if i want to search file from whole computer not just in one directory like "C:/scripts"

objDialog.InitialDir = "C:\Scripts"

(in reply to wetarded1)
 
 
Post #: 16
 
 Re: select directory box - 6/9/2005 9:50:55 PM   
  Zifter


Posts: 318
Score: 0
Joined: 1/5/2005
From: Belgium
Status: offline
If you want to search for a particular file somewhere on the computer, you better use a FileSystemObject or a WMI query.
This dialog is used to give a user the ability the select a file from his/her computer, not to search for files.

The filter property of the dialog is used to make it easier for the user to find a specific type of file.
If you want to filter for files starting with an "A", you could use this:
objDialog.Filter = "Files starting with A|A*.*"

HTH

(in reply to wetarded1)
 
 
Post #: 17
 
 Re: select directory box - 6/9/2005 11:15:42 PM   
  kya_karey

 

Posts: 39
Score: 0
Joined: 5/11/2005
From: India
Status: offline
And what i need to do if i want to search file from whole computer not perticular Drive like.

objDialog.InitialDir = "C:\Scripts"


WHat i need to write if i want to serach from whole computer

(in reply to wetarded1)
 
 
Post #: 18
 
 Re: select directory box - 6/10/2005 12:00:04 AM   
  Zifter


Posts: 318
Score: 0
Joined: 1/5/2005
From: Belgium
Status: offline
The dialog is not designed to search for files. It is designed to let a user select a file.
The filter property and the initialdir property are there to make it easier for the user to find the file he/she wants to select, not for searching for a file.

If you want to search for a file, you can use the FileSystemObject to iterate through each folder and check each file if it meets your search requirements.

(in reply to wetarded1)
 
 
Post #: 19
 
 Re: select directory box - 6/10/2005 1:26:02 AM   
  kya_karey

 

Posts: 39
Score: 0
Joined: 5/11/2005
From: India
Status: offline
Would you please provide me script for that b'coz i tried hard but couldnt able to find anything

If you can provide me this scipt it will be very thankful to u

(in reply to wetarded1)
 
 
Post #: 20
 
 
Page:   [1] 2   next >   >>
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> select directory box Page: [1] 2   next >   >>
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts