Click here to Skip to main content
15,898,938 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Ok to start I would like to have the user select a root directory from a combobox (Example, "C:\"). Once that happens the start button is enabled and the text file with my loaded file names is displayed in a textbox. The user clicks start to scan the C drive and the label shows the directory and file name from the text file that the computer is looking for.........

I am no good with recursion and have been trying to learn it for days. I get the idea of recursion and know it may be the most efficient way to scan a computers folders and sub folders but what I truly need is a full example word for word and what object controls what line of code...... Please I am desperate to understand recursion and need help to make my scanner search the entire directory and not just one level.
Posted
Updated 17-Oct-10 21:37pm
v3
Comments
Gurpreet_Fusion 17-Dec-12 1:14am    
While i am scaning the C or D directory i am getting a access denied error.. How can i solve this error

While I recommend that you try to learn recursion, actually it's not needed here. The GetFiles method in the IO namespace will let you find all files in a given directory AND it's subdirectories.

Something like this:

VB
Imports System.IO

Dim dir As New DirectoryInfo("C:\")
For Each foundFile As FileInfo In dir.GetFiles("*.*", SearchOption.AllDirectories)
    'Do Magic here

Next foundFile


In this case, the AllDirectories flag specifies that it should loop through all subdirectories recursively...
 
Share this answer
 
v4
Comments
Dale 2012 18-Oct-10 4:02am    
Thank you so much for that....... I thought my only way out of this one would be recrusion. I am in need of some guidance when placing this code into effect.... For example.... is your get file code needed in the form load? or maybe the start button click event? please advise or if possible provide a code with the given code to some form objects.....
Johnny J. 18-Oct-10 4:09am    
In your scenario above, you would put it in the buttons click event. My recommendation is that you disable the button while the scanning is running and enable it again when the scanning is done... Just to make sure the user doesn't click it and start another scan while one scan is already in progress.
Dale 2012 18-Oct-10 4:29am    
please you sound very well versed in this topic and it means everything to my project to do this so if i might add one last request

would you please spoon feed me on this one?? :(

I have a combobox that reads all root dirs (combobox1.items.addrange(system.io.directory.getlogicaldrives)
then the user clicks a root dir and the start scan button is enabled
also at this point the text file with the names of the files i wish to find is displayed in the textbox.
I dont know what else to add here please help
Dale 2012 18-Oct-10 4:31am    
The get file method seems very promising but I need the search to check all directories with the names in my text file...
any suggestions or code to help me?
Johnny J. 18-Oct-10 4:32am    
Sorry, Dale, but I don't quite understand what it is you're tyring to do and what role the textbox with the file name plays in the scenario...
An example (written just for you!): "Directory.GetFiles Method (String)"[^] at MSDN.
:-)
 
Share this answer
 
Comments
Dale 2012 18-Oct-10 4:03am    
this will help greatly thank you!! but if possible would you write a search function that will scan for names with a text file..... the names i wish to find are in the text file.....definition scanner
Johnny J. 18-Oct-10 4:10am    
Oh yes, can't you do that c? You can put it on MSDN with the other article... ;-)
Dale 2012 18-Oct-10 4:33am    
please johnny will you provide a code that searches all subfolders when the user selects a root dir from a combobox? my scanner is a definition type scanner that checks for the names using a text file

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900