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???
Printable View
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???
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 :p
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
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
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
didnt work.... how do i display the results?? becuase i need to locate the .vbp's then store themn in C:\VB Projects
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.:p
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
error..... user defined type not defined .....
/vbcode
Set FSys = New FileSystemObject
n00b1337
You have to do ALL the steps:
Quote:
Of course add the FileSystemObject reference to your code (Microsofts Scripting Runtime)
Reading is underated...
hehe ok im trying.... im young and not to greatly experienced... so im trying to make the code work...
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
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????
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?
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
n00b1337
No you did not dim them correctly. Why did you change from the code I gave you?
its saying theres no such thing as diming as folder or file?? im running vb6.0? i duno... im getting farther tho brb
n00b1337
Download the project and open that (Can't trust your typing):bigyello:
Omg it is sooo messed up.... i dled urs.... it works.... i deleted mine..... pasted ur and it says that ...
Error: User-defined not DefinedVB Code:
Option Explicit Dim FSys As FileSystemObject
Umm i Copy and pasted it just the way u said
n00b1337
What part of this don't you get?Quote:
Of course add the FileSystemObject reference to your code (Microsofts Scripting Runtime)
or this?Quote:
Give this a try, you will need the FileSystemObject reference in your project.
It will not work without it? The project I uploaded works doesn't it? It has the reference.
Bingo.... hehe thats what i need... how do i add that in tho? im stuck on that
n00b1337
Go to Projects->References
and select the Microsoft Scripting Runtime
and Walaaa....
Omg thank you soo much for ur time and patience :bigyello: U are the Vb guru in my eyes and i will always come ot u for help
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?
n00b1337
I don't follow...
Could you explain better.
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
VB Code:
Private Sub List1_Click() Label1.Caption = List1.List(List1.ListIndex) End Sub
awesome thank you very much