Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Searching for a folder

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

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Searching for a folder
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Searching for a folder - 6/9/2005 3:05:52 AM   
  snanuwa

 

Posts: 5
Score: 0
Joined: 6/9/2005
From:
Status: offline
Hi,

IÒm trying to create a search function that takes in a string value and returns a Boolean.

The function takes in a search string, it then search predefined drive to search for any folders named or partly named whatÒs in the search string

E.g. folder name could be '67829 Project 1Ò and the search string is 67829 the function should pick up that folder and return a True otherwise false.

I canÒt code searching for a part of a folder name.


Code so far

''''''''''''''''
Function CheckFolderExists(sFolderName)

Dim FileSystemObject

Set FileSystemObject = CreateObject("Scripting.FileSystemObject")

sFolderName = trim(sFolderName)
sFolderName = sFolderName + " "

If (FileSystemObject.FolderExists(sFolderName)) Then
CheckFolderExists = True
msgbox "true " + sFolderName
Else
CheckFolderExists = False
msgbox "false " + sFolderName
End If

Set FileSystemObject = Nothing

End Function
''''''''''''''''

Any more information please email and any help will be greatly appreciated
Thanks
 
 
Post #: 1
 
 Re: Searching for a folder - 6/9/2005 7:40:39 AM   
  didorno

 

Posts: 361
Score: 0
Joined: 2/12/2005
From:
Status: offline
Can you use the "Like" option as in the next code ?

' Returns a list of all the folders whose path begins with C:\S. This script runs only under Windows XP or Windows .NET Server.

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colFolders = objWMIService.ExecQuery _
("Select * from Win32_Directory where Name Like '%c:\\S%'")
For Each objFolder in colFolders
Wscript.Echo "Name: " & objFolder.Name
Next

Maybe you can play with this option to see how it works.
Good luck !

< Message edited by didorno -- 7/20/2005 6:52:23 AM >

(in reply to snanuwa)
 
 
Post #: 2
 
 Re: Searching for a folder - 6/9/2005 10:36:18 PM   
  snanuwa

 

Posts: 5
Score: 0
Joined: 6/9/2005
From:
Status: offline
Thanks, that is excellent.
How do I search for just the root folders and leave out the subfolders?

Thanks

(in reply to snanuwa)
 
 
Post #: 3
 
 Re: Searching for a folder - 6/11/2005 12:10:04 AM   
  didorno

 

Posts: 361
Score: 0
Joined: 2/12/2005
From:
Status: offline
Can you use an If-statement to check how many "\" are present in each found name to make an additional selection between Root and subfolders ?

(in reply to snanuwa)
 
 
Post #: 4
 
 Re: Searching for a folder - 6/13/2005 12:50:35 AM   
  snanuwa

 

Posts: 5
Score: 0
Joined: 6/9/2005
From:
Status: offline
Hi,

I have this at the moment..


search = "o"
found = false

strComputer = "pc2002-eh060"

Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colFolders = objWMIService.ExecQuery (" Select * from Win32_Directory where Name Like '%d:\\" + search + "%' ")


For Each objFolder in colFolders

'Enable Error Handling
On Error Resume Next

if instr(4, objFolder.Name, "\") < 3 then
Wscript.Echo "Name: " & objFolder.Name + " folder found"
found = true
end if

Next


If the search finds no matches I want to throw up a message box saying "Not found"
But it doesn't work if add another if statements.
Any help?

Thanks

(in reply to snanuwa)
 
 
Post #: 5
 
 Re: Searching for a folder - 6/13/2005 5:22:01 AM   
  didorno

 

Posts: 361
Score: 0
Joined: 2/12/2005
From:
Status: offline
quote:
Originally posted by snanuwa
..............
if instr(4, objFolder.Name, "\") < 3 then
Wscript.Echo "Name: " & objFolder.Name + " folder found"
found = true
end if
..............



The condition in the If statement above becomes only True if "\" is not present at or after the 4th position. But then you can compare with 0 and do not need the value 3. Is that what you want ?

Can you give a few examples of acceptable and non-acceptable folders ? Then better help is possible.

quote:

................
If the search finds no matches I want to throw up a message box saying "Not found"
But it doesn't work if add another if statements.
Any help?

Thanks


Do you mean the use of

If expression = true Then
Do1
Else
WScript.Echo "Folder NOT found"
End If

(in reply to snanuwa)
 
 
Post #: 6
 
 
 
  

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 >> Searching for a folder Page: [1]
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