Ivan G.
Ivan G.

Reputation: 5225

File/directory search

Any idea how to easily support file search patterns in your software, like **, *, ?

For example subfolder/**/?svn - search in all levels of subfolder for files/folders ending in "svn" 4 characters in total.

full description: http://nant.sourceforge.net/release/latest/help/types/fileset.html

Upvotes: 0

Views: 266

Answers (3)

Manatherin
Manatherin

Reputation: 4187

If you load the directory as a directory info e.g.

DirectoryInfo directory = new DirectoryInfo(folder);

then do a search for files like this

IEnumerable<FileInfo> fileInfo = directory.GetFiles("*.svn", SearchOption.AllDirectories);

this should get you a list of fileInfo which you can manipulate

to get all subdirectories you can do the same e.g

IEnumerable<DirectoryInfo> dirInfo = directory.GetDirectories("*svn", SearchOption.AllDirectories);

anyway that should give a idea of how i'd do it. Also because fileInfo and dirInfo are IEnumerable you can add linq where queries etc. to filter results

Upvotes: 2

user623879
user623879

Reputation: 4142

A mix of regex and recursion should do the trick.

Another trick might be to spawn a thread for every folder or set of folders and have the thread proceed checking one more level down. This could be beneficial to speed up the process a bit.

The reason I say this is because that is highly io bound process to check folders etc. So many threads will allow you to submit more disk requests faster thus improving the speed.

Upvotes: 1

Dan F
Dan F

Reputation: 12051

This might sound silly, but have you considered downloading the nant source code to see how they did it?

Upvotes: 0

Related Questions