|
-
Mar 21st, 2006, 10:19 PM
#1
Thread Starter
Lively Member
Searching Hard Drive For Filenames
ok, well what im trying to do is write a program that checks in every folder one the hard drive for file names that are contained in a text file. i can probably manage to figure out how to load the file names into an array "name(999999)" but what i want to do is make a loop that checks through each file in every folder on the hard drive to see if the name matches any in the array without being case sensitive. can someone show me how to do this? i would really appreciate it.
also, if you have some extra time, could you show me an easy way to load the names from the text file which will be in the file like
file1name
file2name
file3name
and so on, and make each different name go into the array like, the first filename would be contained in name(1) and the second in name(2) etc. Thanks!
-
Mar 21st, 2006, 11:01 PM
#2
Re: Searching Hard Drive For Filenames
JayWalker,
Look here for a project named Scan All Folders on Disk for Files. You can use a collection to store your filenames that you want to search for and test with the collection.
-
Mar 22nd, 2006, 02:43 PM
#3
Thread Starter
Lively Member
Re: Searching Hard Drive For Filenames
thank you much for the code, i will probably use some code from the scanfolders2 project, since its about 66% faster, but how would i use that code to search for hundreds of individual filenames at a time rather than just an extension, and display the matching paths in a list box?
im still somewhat inexperienced at vb and i dont know how to use a collection. if you could help it would be great!
-
Mar 22nd, 2006, 05:39 PM
#4
Re: Searching Hard Drive For Filenames
JayWalker,
Since the code looks thru each folder, just place code just after it retrieves the filename to check the Array or Collection (I like the latter) for the filename.
To use a collection:
VB Code:
Dim colFilenames as Collection
Dim tempFilename as String
Set colFilename = New Collection
colFilename.Add Filename,Filename 'Add to the collection. Use the filename as the key and data
...
On Error Resume Next
Set tempName = colFilename.Item(Filename) ' Attempt to retrieve filename from collection. If error occurs, it is not there.
If Err.Number = 0 Then ' No error then do what you need to here
End If
On Error GoTo 0
This was done off the top of my head and may need a tweak or two. But you should get the idea.
-
Mar 22nd, 2006, 09:35 PM
#5
Thread Starter
Lively Member
Re: Searching Hard Drive For Filenames
sorry, im really new to collections and messing with the hard drive in any way through vb. i dont know where i should put the collection or how to use it because i dont understand where in the code it actually check for a match. i saw how it looks for .vbp file but i dont know how to make it search for a bunch of file names... help please?
-
Mar 24th, 2006, 04:32 AM
#6
Re: Searching Hard Drive For Filenames
JayWalker,
You check for the filename after each call to FindNextFile and FindFirstFile. If you don't understand collections then call a routine that will loop thru the filename you want to search for and check for the filename there.
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
|