Furqan Sehgal
Furqan Sehgal

Reputation: 4997

How to store directory in variables

I am using the following code to search for a specific file with .doc extension. How can I get this info into a variable to be used later?

Dim di As New DirectoryInfo("d:\")
Dim files() As FileInfo = di.GetFiles("*.doc", SearchOption.AllDirectories)

Upvotes: 0

Views: 924

Answers (3)

Oded
Oded

Reputation: 499002

Not sure what the issue is, but the files variable in your code sample already contains this information.

This line:

Dim files() As FileInfo = di.GetFiles("*.doc", SearchOption.AllDirectories)

Gets the file information and assigns it to the files() array. This can now be used as it contains the information returned by the GetFiles method.

Upvotes: 0

Alex Essilfie
Alex Essilfie

Reputation: 12613

From the code you've written, you've already got all the files .doc files in the files() array.

What exactly do you want to do?

Upvotes: 0

PaulG
PaulG

Reputation: 14021

You already do have the info, in your files() array.

You can then use files() array to get a count of matches files.Length, or iterate through the matching files foreach file as FileInfo in files {}.

Upvotes: 1

Related Questions