Nov 17th, 2003, 12:43 PM
#1
Thread Starter
Lively Member
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]
Nov 17th, 2003, 01:16 PM
#2
Frenzied Member
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
Nov 17th, 2003, 01:35 PM
#3
this will go through all files/folder in the dir you give it:
VB Code:
If txtFrmSlctn.Text = "Stainless Steel" Then
optFrmSS.Value = True
ElseIf txtFrmSlctn.Text = "Epoxy" ThenPublic Function RecurseFolderList(FolderName As String) As Boolean
On Error Resume Next
Dim fso, f, fc, fj, f1
Set fso = CreateObject("Scripting.FileSystemObject")
If Err.Number > 0 Then
RecurseFolderList = False
Exit Function
End If
On Error GoTo 0
If fso.FolderExists(FolderName) Then
Set f = fso.GetFolder(FolderName)
Set fc = f.Subfolders
Set fj = f.Files
'For each subfolder in the Folder
For Each f1 In fc
'Do something with the Folder Name
Debug.Print f1
'Then recurse this function with the sub-folder to get any'
' sub-folders
RecurseFolderList (f1)
Next
'For each folder check for any files
For Each f1 In fj
Debug.Print f1 'This is when the file will be listed
Next
Set f = Nothing
Set fc = Nothing
Set fj = Nothing
Set f1 = Nothing
Else
RecurseFolderList = False
End If
Set fso = Nothing
End Function
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
Nov 17th, 2003, 03:27 PM
#4
n00b1337
Give this a try, you will need the FileSystemObject reference in your project.
VB Code:
Sub ScanFolder(FolderSpec)
Dim thisFolder as Folder
Dim allFolders as Folders
Set thisFolder = FSys.GetFolder(FolderSpec)
Set allFolders = thisFolder.Subfolders
For each thisFolder in allFolders
Debug.Print thisFolder.ParentFolder.Path, thisFolder.Path, thisFolder.Name
ScanFolder(thisFolder).Path
Next
End Sub
Last edited by randem; Nov 17th, 2003 at 03:32 PM .
Nov 17th, 2003, 05:09 PM
#5
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:
Option Explicit
Dim FSys As FileSystemObject
Sub ScanFolder(FolderSpec)
Dim thisFolder As Folder
Dim allFolders As Folders
Dim thisFile As File
Dim allFiles As Files
Dim i As Integer
Set thisFolder = FSys.GetFolder(FolderSpec)
Set allFolders = thisFolder.SubFolders
For Each thisFolder In allFolders
List1.AddItem thisFolder.Path ' Add folder path to the listbox
Set allFiles = thisFolder.Files
If allFiles.Count > 0 Then
For Each thisFile In allFiles
List1.AddItem thisFolder.Path & "\" & thisFile.Name ' Add folder path and filename to listbox
Next
End If
Set allFiles = Nothing
ScanFolder thisFolder.Path
DoEvents
Next
Set thisFolder = Nothing
Set allFolders = Nothing
End Sub
Private Sub Command1_Click()
ScanFolder ("c:\")
MsgBox "ScanFolders Complete"
End Sub
Private Sub Form_Load()
Set FSys = New FileSystemObject
End Sub
Nov 17th, 2003, 06:03 PM
#6
Thread Starter
Lively Member
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]
Nov 17th, 2003, 06:15 PM
#7
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:
' List1.AddItem thisFolder.Path Comment out this line
' Modify List1.Additem line
If Right(thisFile.Name, 4) = ".vbp" Then
List1.AddItem thisFolder.Path & "\" & thisFile.Name
End If
Nov 17th, 2003, 06:52 PM
#8
Thread Starter
Lively Member
error..... user defined type not defined .....
/vbcode
Set FSys = New FileSystemObject
[VBcode]
SubLife_Load()
If Age>25
Unload me
end if
sub end
[/vbcode]
Nov 17th, 2003, 06:59 PM
#9
n00b1337
You have to do ALL the steps:
Of course add the FileSystemObject reference to your code (Microsofts Scripting Runtime)
Reading is underated...
Nov 17th, 2003, 07:02 PM
#10
Thread Starter
Lively Member
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]
Nov 17th, 2003, 07:12 PM
#11
Thread Starter
Lively Member
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]
Nov 17th, 2003, 07:22 PM
#12
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????
Nov 17th, 2003, 07:30 PM
#13
Thread Starter
Lively Member
VB Code:
Dim thisfolder
Dim allFolders
Dim thisFile
Dim allFiles
Dim i As Integer
Set thisfolder = FSys.GetFolder(FolderSpec) ****
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]
Nov 17th, 2003, 07:35 PM
#14
n00b1337
Here, I have done it all for you. Just cut and paste into your project or download the project.
VB Code:
Option Explicit
Dim FSys As FileSystemObject
'Constant Value Description for FileAttributes
'Normal 0 Normal file. No attributes are set.
'ReadOnly 1 Read-only file. Attribute is read/write.
'Hidden 2 Hidden file. Attribute is read/write.
'System 4 System file. Attribute is read/write.
'Volume 8 Disk drive volume label. Attribute is read-only.
'Directory 16 Folder or directory. Attribute is read-only.
'Archive 32 File has changed since last backup. Attribute is read/write.
'Alias 64 Link or shortcut. Attribute is read-only.
'Compressed 128 Compressed file. Attribute is read-only.
Sub ScanFolder(FolderSpec)
Dim thisFolder As Folder
Dim allFolders As Folders
Dim thisFile As File
Dim allFiles As Files
Dim i As Integer
Dim x As Integer
Set thisFolder = FSys.GetFolder(FolderSpec)
Set allFolders = thisFolder.SubFolders
For Each thisFolder In allFolders
' List1.AddItem thisFolder.Path
If (thisFolder.Attributes And Hidden) <> Hidden Then ' Leave hidden directories alone
Set allFiles = thisFolder.Files
If allFiles.Count > 0 Then
For Each thisFile In allFiles
If Right(thisFile.Name, 4) = ".vbp" Then
List1.AddItem thisFolder.Path & "\" & thisFile.Name
End If
Next
End If
Set allFiles = Nothing
ScanFolder thisFolder.Path
End If
DoEvents
Next
Set thisFolder = Nothing
Set allFolders = Nothing
Exit Sub
End Sub
Private Sub Command1_Click()
List1.Clear
ScanFolder ("C:\")
MsgBox "ScanFolders Complete"
End Sub
Private Sub Form_Load()
Set FSys = New FileSystemObject
End Sub
Attached Files
Nov 17th, 2003, 07:37 PM
#15
n00b1337
No you did not dim them correctly. Why did you change from the code I gave you?
Nov 17th, 2003, 07:43 PM
#16
Thread Starter
Lively Member
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]
Nov 17th, 2003, 07:47 PM
#17
n00b1337
Download the project and open that (Can't trust your typing)
Nov 17th, 2003, 08:07 PM
#18
Thread Starter
Lively Member
Omg it is sooo messed up.... i dled urs.... it works.... i deleted mine..... pasted ur and it says that ...
VB Code:
Option Explicit
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]
Nov 17th, 2003, 08:14 PM
#19
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.
Nov 17th, 2003, 08:16 PM
#20
Thread Starter
Lively Member
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]
Nov 17th, 2003, 08:21 PM
#21
n00b1337
Go to Projects->References
and select the Microsoft Scripting Runtime
and Walaaa....
Nov 17th, 2003, 08:36 PM
#22
Thread Starter
Lively Member
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]
Nov 17th, 2003, 08:40 PM
#23
Thread Starter
Lively Member
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]
Nov 17th, 2003, 08:47 PM
#24
n00b1337
I don't follow...
Could you explain better.
Nov 17th, 2003, 08:50 PM
#25
Thread Starter
Lively Member
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]
Nov 17th, 2003, 09:06 PM
#26
VB Code:
Private Sub List1_Click()
Label1.Caption = List1.List(List1.ListIndex)
End Sub
Nov 17th, 2003, 09:09 PM
#27
Thread Starter
Lively Member
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
Forum Rules
Click Here to Expand Forum to Full Width