Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dir () search function

Status
Not open for further replies.

Govnor

Technical User
Sep 3, 2002
55
GB
Hi,

I am using the Dir() to search files on my hard drive then move them to another location.

Snip of Code shown below; this code is in a DO Loop

Dim StrDir As String
StrDir = Dir(App.Path & "\" & FileNameTxtBx.Text)

First problem is; I would like the program to search my whole hard drive and all sub folders! Can this be done?

Thank you
Manraj
 
Hi,

I'am open to all options, my main aim is to write a program that searches my hard drive finds the files I want! Then I want to change the names of these files and move it to a new location.

So, yes please, could you show me how to search for files using IO namespace.

Thanks
 
The first thing to do is get all the drives on your computer:

IO.Directory.GetLogicalDrives

this returns a string array of drives like c:\ d:\ e:
So,

-
Dim drive As String

For Each drive In IO.Directory.GetLogicalDrives()

Next drive
-

Next, Send each drive to a recursive subroutine,

-
RecursiveSearch(drive)
-

So,

-
Dim drive As String

For Each drive In IO.Directory.GetLogicalDrives()
RecursiveSearch(drive)
Next drive
-

Next, in this subroutine will be two things that it does, 1. Calls itself with every subdirectory that it finds 2. Works on the files.

So,

-
Sub RecursiveSearch(ByVal path As String)
Dim dir As String
For Each dir In Directory.GetDirectories(path)
RecursiveSearch(dir)
Next

For Each fle In Directory.GetFiles(path)
'This is where you work on the files.
Next

End Sub
-

i hope that isnt too confusing, tell me if you have any questions
 
Hi,

I have finished my program and it works with IO.Directory command.

it helped me alot.

thanks phunugus
 
Hi,

I'm trying to do something similair but I'm wanting to find only certin file extentions. And how did you get around the error that happens when you are denied access to a folder on the drive?

Any help would be great..

Thanks...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top