Results 1 to 27 of 27

Thread: Searching the harddrive

  1. #1

    Thread Starter
    Lively Member n00b1337's Avatar
    Join Date
    Sep 2003
    Location
    Berlin Connecticut
    Posts
    67

    Searching the harddrive

    Ok i need to konw how to Search the Hard drive for files... im going ot make a program that searches the hd for .vbps and puts them into a subdir. how would i make hte computer search???
    [VBcode]
    SubLife_Load()
    If Age>25
    Unload me
    end if
    sub end

    [/vbcode]

  2. #2
    Frenzied Member agmorgan's Avatar
    Join Date
    Dec 2000
    Location
    Lurking
    Posts
    1,383
    This thread has a solution http://www.vbforums.com/showthread.p...arch+har+drive
    Trouble is, its not simple to follow through.
    If you do a search for "search hard drive", other solutions come up
    and they aren't that simple either

  3. #3
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390
    this will go through all files/folder in the dir you give it:

    VB Code:
    1. If txtFrmSlctn.Text = "Stainless Steel" Then
    2.     optFrmSS.Value = True
    3.     ElseIf txtFrmSlctn.Text = "Epoxy" ThenPublic Function RecurseFolderList(FolderName As String)  As Boolean
    4.  
    5. On Error Resume Next
    6. Dim fso, f, fc, fj, f1
    7.  
    8.  Set fso = CreateObject("Scripting.FileSystemObject")
    9.  
    10. If Err.Number > 0 Then
    11.     RecurseFolderList = False
    12.     Exit Function
    13. End If
    14.  
    15. On Error GoTo 0
    16. If fso.FolderExists(FolderName) Then
    17.  
    18.     Set f = fso.GetFolder(FolderName)
    19.     Set fc = f.Subfolders
    20.     Set fj = f.Files
    21.     'For each subfolder in the Folder
    22.      For Each f1 In fc
    23.      'Do something with the Folder Name
    24.      Debug.Print f1
    25.        'Then recurse this function with the sub-folder to get any'
    26.       ' sub-folders
    27.        RecurseFolderList (f1)
    28.      Next
    29.    
    30.        'For each folder check for any files
    31.        For Each f1 In fj
    32.            Debug.Print f1 'This is when the file will be listed
    33.        Next
    34.    
    35.     Set f = Nothing
    36.     Set fc = Nothing
    37.     Set fj = Nothing
    38.     Set f1 = Nothing
    39.  
    40. Else
    41.     RecurseFolderList = False
    42. End If
    43.  
    44. Set fso = Nothing
    45.  
    46. End Function
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  4. #4
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385
    n00b1337


    Give this a try, you will need the FileSystemObject reference in your project.

    VB Code:
    1. Sub ScanFolder(FolderSpec)
    2. Dim thisFolder as Folder
    3. Dim allFolders as Folders
    4.  
    5.    Set thisFolder = FSys.GetFolder(FolderSpec)
    6.    Set allFolders = thisFolder.Subfolders
    7.  
    8.    For each thisFolder in allFolders
    9.    
    10.       Debug.Print thisFolder.ParentFolder.Path, thisFolder.Path, thisFolder.Name
    11.  
    12.       ScanFolder(thisFolder).Path
    13.  
    14.    Next
    15. End Sub
    Last edited by randem; Nov 17th, 2003 at 03:32 PM.

  5. #5
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385
    n00b1337

    Sorry, I was rushing out the door and did not give you a complete view of things. Cut and paste this entire code excert into an empty form. Put a CommandButton and a ListBox on the form, then run the code.
    Of course add the FileSystemObject reference to your code (Microsofts Scripting Runtime)

    VB Code:
    1. Option Explicit
    2.  
    3. Dim FSys As FileSystemObject
    4.  
    5.  
    6. Sub ScanFolder(FolderSpec)
    7.  
    8. Dim thisFolder As Folder
    9. Dim allFolders As Folders
    10. Dim thisFile As File
    11. Dim allFiles As Files
    12.  
    13. Dim i As Integer
    14.  
    15.    Set thisFolder = FSys.GetFolder(FolderSpec)
    16.    Set allFolders = thisFolder.SubFolders
    17.    
    18.    
    19.    For Each thisFolder In allFolders
    20.    
    21.       List1.AddItem thisFolder.Path   ' Add folder path to the listbox
    22.       Set allFiles = thisFolder.Files
    23.    
    24.       If allFiles.Count > 0 Then
    25.         For Each thisFile In allFiles
    26.            List1.AddItem thisFolder.Path & "\" & thisFile.Name   ' Add folder path and filename to listbox
    27.  
    28.         Next
    29.       End If
    30.      
    31.       Set allFiles = Nothing
    32.      
    33.       ScanFolder thisFolder.Path
    34.       DoEvents
    35.      
    36.    Next
    37.    
    38.    Set thisFolder = Nothing
    39.    Set allFolders = Nothing
    40.    
    41. End Sub
    42.  
    43. Private Sub Command1_Click()
    44.  
    45.    ScanFolder ("c:\")
    46.    MsgBox "ScanFolders Complete"
    47.    
    48. End Sub
    49.  
    50. Private Sub Form_Load()
    51.  
    52.    Set FSys = New FileSystemObject
    53.  
    54. End Sub

  6. #6

    Thread Starter
    Lively Member n00b1337's Avatar
    Join Date
    Sep 2003
    Location
    Berlin Connecticut
    Posts
    67
    didnt work.... how do i display the results?? becuase i need to locate the .vbp's then store themn in C:\VB Projects
    [VBcode]
    SubLife_Load()
    If Age>25
    Unload me
    end if
    sub end

    [/vbcode]

  7. #7
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385
    What did not work? Was it unemployed? What? The code I gave you displays every file on you PC. What do you mean did not work? you have to do some of the work.

    Change the list1additem to this:

    VB Code:
    1. '      List1.AddItem thisFolder.Path  Comment out this line
    2.  
    3. ' Modify List1.Additem line
    4.  
    5.            If Right(thisFile.Name, 4) = ".vbp" Then
    6.               List1.AddItem thisFolder.Path & "\" & thisFile.Name
    7.            End If

  8. #8

    Thread Starter
    Lively Member n00b1337's Avatar
    Join Date
    Sep 2003
    Location
    Berlin Connecticut
    Posts
    67
    error..... user defined type not defined .....
    /vbcode
    Set FSys = New FileSystemObject
    [VBcode]
    SubLife_Load()
    If Age>25
    Unload me
    end if
    sub end

    [/vbcode]

  9. #9
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385
    n00b1337


    You have to do ALL the steps:

    Of course add the FileSystemObject reference to your code (Microsofts Scripting Runtime)

    Reading is underated...

  10. #10

    Thread Starter
    Lively Member n00b1337's Avatar
    Join Date
    Sep 2003
    Location
    Berlin Connecticut
    Posts
    67
    hehe ok im trying.... im young and not to greatly experienced... so im trying to make the code work...
    [VBcode]
    SubLife_Load()
    If Age>25
    Unload me
    end if
    sub end

    [/vbcode]

  11. #11

    Thread Starter
    Lively Member n00b1337's Avatar
    Join Date
    Sep 2003
    Location
    Berlin Connecticut
    Posts
    67
    ahhh im soooo stuck on this one area
    [Highlight=VB]
    Sub ScanFolder(FolderSpec) ' what do i do here... i cant figure it out

    Dim thisFolder As fold
    Dim allFolders As Folders
    Dim thisFile As File
    Dim allFiles As Files
    and these i dont get it
    [VBcode]
    SubLife_Load()
    If Age>25
    Unload me
    end if
    sub end

    [/vbcode]

  12. #12
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385
    n00b1337

    You have to close your vbcode tags also. What do you mean make it work what error are you getting now? I don't understand what do you do here????

  13. #13

    Thread Starter
    Lively Member n00b1337's Avatar
    Join Date
    Sep 2003
    Location
    Berlin Connecticut
    Posts
    67
    VB Code:
    1. Dim thisfolder
    2. Dim allFolders
    3. Dim thisFile
    4. Dim allFiles
    5.  
    6. Dim i As Integer
    7.  
    8.    Set thisfolder = FSys.GetFolder(FolderSpec)  ****
    9.    Set allFolders = thisfolder.SubFolders


    this line **** = Runtime error '424'
    Object required
    are thoose Dimmed Correctly?
    [VBcode]
    SubLife_Load()
    If Age>25
    Unload me
    end if
    sub end

    [/vbcode]

  14. #14
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385
    n00b1337

    Here, I have done it all for you. Just cut and paste into your project or download the project.

    VB Code:
    1. Option Explicit
    2.  
    3. Dim FSys As FileSystemObject
    4.  
    5. 'Constant Value Description for FileAttributes
    6.  
    7. 'Normal     0 Normal file. No attributes are set.
    8. 'ReadOnly   1 Read-only file. Attribute is read/write.
    9. 'Hidden     2 Hidden file. Attribute is read/write.
    10. 'System     4 System file. Attribute is read/write.
    11. 'Volume     8 Disk drive volume label. Attribute is read-only.
    12. 'Directory  16 Folder or directory. Attribute is read-only.
    13. 'Archive    32 File has changed since last backup. Attribute is read/write.
    14. 'Alias      64 Link or shortcut. Attribute is read-only.
    15. 'Compressed 128 Compressed file. Attribute is read-only.
    16.  
    17.  
    18. Sub ScanFolder(FolderSpec)
    19.  
    20. Dim thisFolder As Folder
    21. Dim allFolders As Folders
    22. Dim thisFile As File
    23. Dim allFiles As Files
    24.  
    25. Dim i As Integer
    26. Dim x As Integer
    27.  
    28.    Set thisFolder = FSys.GetFolder(FolderSpec)
    29.    Set allFolders = thisFolder.SubFolders
    30.    
    31.  
    32.    For Each thisFolder In allFolders
    33.    
    34. '      List1.AddItem thisFolder.Path
    35.      
    36.       If (thisFolder.Attributes And Hidden) <> Hidden Then   ' Leave hidden directories alone
    37.         Set allFiles = thisFolder.Files
    38.        
    39.         If allFiles.Count > 0 Then
    40.           For Each thisFile In allFiles
    41.              If Right(thisFile.Name, 4) = ".vbp" Then
    42.                 List1.AddItem thisFolder.Path & "\" & thisFile.Name
    43.              End If
    44.           Next
    45.         End If
    46.        
    47.         Set allFiles = Nothing
    48.         ScanFolder thisFolder.Path
    49.       End If
    50.  
    51.       DoEvents
    52.      
    53.    Next
    54.    
    55.    Set thisFolder = Nothing
    56.    Set allFolders = Nothing
    57.    Exit Sub
    58.    
    59. End Sub
    60.  
    61. Private Sub Command1_Click()
    62.  
    63.    List1.Clear
    64.    ScanFolder ("C:\")
    65.    MsgBox "ScanFolders Complete"
    66.    
    67. End Sub
    68.  
    69. Private Sub Form_Load()
    70.  
    71.    Set FSys = New FileSystemObject
    72.  
    73. End Sub
    Attached Files Attached Files

  15. #15
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385
    n00b1337

    No you did not dim them correctly. Why did you change from the code I gave you?

  16. #16

    Thread Starter
    Lively Member n00b1337's Avatar
    Join Date
    Sep 2003
    Location
    Berlin Connecticut
    Posts
    67
    its saying theres no such thing as diming as folder or file?? im running vb6.0? i duno... im getting farther tho brb
    [VBcode]
    SubLife_Load()
    If Age>25
    Unload me
    end if
    sub end

    [/vbcode]

  17. #17
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385
    n00b1337


    Download the project and open that (Can't trust your typing)

  18. #18

    Thread Starter
    Lively Member n00b1337's Avatar
    Join Date
    Sep 2003
    Location
    Berlin Connecticut
    Posts
    67
    Omg it is sooo messed up.... i dled urs.... it works.... i deleted mine..... pasted ur and it says that ...

    VB Code:
    1. Option Explicit
    2.  
    3. Dim FSys As FileSystemObject
    Error: User-defined not Defined


    Umm i Copy and pasted it just the way u said
    [VBcode]
    SubLife_Load()
    If Age>25
    Unload me
    end if
    sub end

    [/vbcode]

  19. #19
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385
    n00b1337


    Of course add the FileSystemObject reference to your code (Microsofts Scripting Runtime)
    What part of this don't you get?

    Give this a try, you will need the FileSystemObject reference in your project.
    or this?

    It will not work without it? The project I uploaded works doesn't it? It has the reference.

  20. #20

    Thread Starter
    Lively Member n00b1337's Avatar
    Join Date
    Sep 2003
    Location
    Berlin Connecticut
    Posts
    67
    Bingo.... hehe thats what i need... how do i add that in tho? im stuck on that
    [VBcode]
    SubLife_Load()
    If Age>25
    Unload me
    end if
    sub end

    [/vbcode]

  21. #21
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385
    n00b1337


    Go to Projects->References

    and select the Microsoft Scripting Runtime

    and Walaaa....

  22. #22

    Thread Starter
    Lively Member n00b1337's Avatar
    Join Date
    Sep 2003
    Location
    Berlin Connecticut
    Posts
    67

    Cool

    Omg thank you soo much for ur time and patience U are the Vb guru in my eyes and i will always come ot u for help
    [VBcode]
    SubLife_Load()
    If Age>25
    Unload me
    end if
    sub end

    [/vbcode]

  23. #23

    Thread Starter
    Lively Member n00b1337's Avatar
    Join Date
    Sep 2003
    Location
    Berlin Connecticut
    Posts
    67
    I need u to help me with one more thing tho.... its much easyer... Can u tell me how to make a Label the Selected Line in the list box?
    [VBcode]
    SubLife_Load()
    If Age>25
    Unload me
    end if
    sub end

    [/vbcode]

  24. #24
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385
    n00b1337

    I don't follow...

    Could you explain better.

  25. #25

    Thread Starter
    Lively Member n00b1337's Avatar
    Join Date
    Sep 2003
    Location
    Berlin Connecticut
    Posts
    67
    ok bare with me hehe.... i now have a label above the listbox...... when i select one of the .vbp's in the list, i want it to be displayed in the label ( For example if i Click one that says (C:\vb\Hi.vbp) i want it so show C:\vb\hi.vbp in the label
    Last edited by n00b1337; Nov 17th, 2003 at 08:57 PM.
    [VBcode]
    SubLife_Load()
    If Age>25
    Unload me
    end if
    sub end

    [/vbcode]

  26. #26
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629
    VB Code:
    1. Private Sub List1_Click()
    2.   Label1.Caption = List1.List(List1.ListIndex)
    3. End Sub
    Like Archer? Check out some Sterling Archer quotes.

  27. #27

    Thread Starter
    Lively Member n00b1337's Avatar
    Join Date
    Sep 2003
    Location
    Berlin Connecticut
    Posts
    67

    Resolved

    awesome thank you very much
    [VBcode]
    SubLife_Load()
    If Age>25
    Unload me
    end if
    sub end

    [/vbcode]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width