borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (how to make label sizes dynamic within a frame)Next Topic (Problem with SQL statement) New Topic New Poll Post Reply
AndreaVB Forum : VB General : Search for a directory containg certain characters
Poster Message
bcbii
Level: Trainee

Registered: 06-04-2005
Posts: 2

icon Search for a directory containg certain characters

Hi,

I am trying to save a document to a sepcific folder.  This folder name will contain a number and a description ie.

c:\345 testing this\

The user will enter the number in the dialog.  There are a lot of folders all with a different number and different description; too many to write an if statement to get the whole folder name.

I have a few ideas, I could generate a list of all the folders in a specified directory, search for the entered number in the list, and return the full folder name.  

Or was thinking I could use a wildcard in the save path for the document.  So the program searches for the only folder with those numbers, something like this:

number = txtNumber.Text 'grab the folder number from a text box

directory = "c:\" & number & " *\document.txt"

once the number has been chosen (say they entered 345 into the text box txtNumber), directory would look like:

c:\345 *\document.txt

Really all i am trying to do is search for a folder whose name contains the entered number, and save the document in that folder

Thank you for your help

12-05-2005 at 09:06 PM
View Profile Send Email to User Show All Posts | Quote Reply
steve_w
Level: Moderator


Registered: 18-04-2003
Posts: 1156
icon Re: Search for a directory containg certain characters

Hi

Try the code below, it does a recursive search on a folder and will look for a match of a folder name.

' include the reference for "Microsoft Scripting Runtime"

Option Explicit

Private FileSaved As Boolean

Private Sub Command1_Click()

    FileSaved = False

    ' replace your start folder here
    '                            v
    Search_folder "c:\windows"

End Sub

Private Sub Search_folder(parent As String)

    Dim fso As FileSystemObject
    Dim mfolder As Folder
    
    Set fso = New FileSystemObject

    Debug.Print parent
    
    ' replace your search number here
    '                                                   v
    If InStr(UCase(parent), UCase("system32")) > 0 Then
    
        '================
        ' save file here
        '================
        
        FileSaved = True
        
    End If
    
    If FileSaved = False Then
        
        For Each mfolder In fso.GetFolder(parent).SubFolders
            
            Search_folder mfolder.Path
            
        Next
        
    End If
    
    Set fso = Nothing

End Sub



Steve  

[Edited by steve_w on 13-05-2005 at 08:05 AM GMT]

13-05-2005 at 07:53 AM
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : VB General : Search for a directory containg certain characters
Previous Topic (how to make label sizes dynamic within a frame)Next Topic (Problem with SQL statement) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder