Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Find Files and folders

9 views
Skip to first unread message

frogman7

unread,
Oct 13, 2006, 5:14:37 PM10/13/06
to
what i am trying to do is something similar to the search that windows
does to find files and folders. I am putting a start directory and
want to find all the file (including the files in the sub folders) so i

can write each line to a master file. i have it working but it uses
loops and it extremely slow. Is there a function that grabs all the
files from a folder and subdirectories?

Spam Catcher

unread,
Oct 13, 2006, 5:29:07 PM10/13/06
to
"frogman7" <frog...@googlemail.com> wrote in news:1160774077.181291.188630
@m7g2000cwm.googlegroups.com:

> can write each line to a master file. i have it working but it uses
> loops and it extremely slow. Is there a function that grabs all the
> files from a folder and subdirectories?

How are you writing out to the file?

Are you concatenating the data before outputting?

frogman7

unread,
Oct 13, 2006, 5:56:26 PM10/13/06
to
I am using streamwriter at present. as i loop through and find the
file i write a string to the file with a return at the end of it. but
maybe that is why it is so slow

tesl...@hotmail.com

unread,
Oct 13, 2006, 6:31:37 PM10/13/06
to

How are you obtaining the directory information? That was the source
of slowdown when I tried something similar recently.

frogman7

unread,
Oct 13, 2006, 7:56:43 PM10/13/06
to
I basically get the top directory and find all the files in that
directory and parse them
then I find all the subdirectories and loop through them doing this
recursively until no more lists it is a while loop inside of a for loop
inside of a for loop but I need to add another loop at the top so it
will be a 4 loop system and that just seems really slow.

I am trying a new approach getting all directories and subs and putting
them in an arraylist then call the find file part using that arraylist.

Do you think this new approach will be faster?

tesl...@hotmail.com

unread,
Oct 13, 2006, 10:17:56 PM10/13/06
to

Actually, I meant what method or commands you were using to get the
directory info from the disk in the first place.

Some of those commands are rather slow, and if your new technique will
reduce calls to those commands, it may well help you out if that's the
bottleneck.

Check a recent thread here, it may have some info that helps you. The
code I posted does a recursive directory listing using two methods,
System.IO.DirectoryInfo and direct API calls, and includes benchmarking
results:

Title: What .NET classes are SLOW vs. API?
http://groups.google.com/group/microsoft.public.dotnet.languages.vb/browse_frm/thread/6930fd7d32d43f79/6e62e68f40049cc4?lnk=st&q=api+methods+slow&rnum=3&hl=en#6e62e68f40049cc4

frogman7

unread,
Oct 14, 2006, 1:48:55 AM10/14/06
to
Sorry I didn't understand

I am using the system.IO.getfiles and getdirectories

I will look at your post and try it.

thanks

Stephany Young

unread,
Oct 14, 2006, 5:57:23 AM10/14/06
to
There are 2 points to be considered here.

The 1st is getting the information in the first place. One of the overloads
of System.IO.Directory.GetFiles allows searching sub-directories thus
allowing you to get all the filenames in a given tree in a single operation.

The 2nd point is that the result of a 'GetFiles' is an array of strings so
there is no need to put the results into another array or indeed write them
to a file individually. The System.String.Join method provides you with a
mechanism to write the entire array to a file in one operation.

In it's simplest terms it becomes:

File.WriteAllText([output filename], String.Join(Environment.Newline,
Directory.GetFiles([start point], "*.*", SearchOption.AllDirectories)))

"frogman7" <frog...@googlemail.com> wrote in message
news:1160804935.7...@i3g2000cwc.googlegroups.com...

tesl...@hotmail.com

unread,
Oct 14, 2006, 3:38:26 PM10/14/06
to
Stephany Young wrote:
> File.WriteAllText([output filename], String.Join(Environment.Newline,
> Directory.GetFiles([start point], "*.*", SearchOption.AllDirectories)))

Wow, that's beautiful. :)

Frogman, it seems the API method I described only shows a speed
advantage if you're also interested in size/dates/attribs. If you just
need the name, Stephany's method matches or beats the speed, and blows
it away in simplicity.

ShaneO

unread,
Oct 14, 2006, 4:33:13 PM10/14/06
to
Stephany Young wrote:
>
> In it's simplest terms it becomes:
>
> File.WriteAllText([output filename], String.Join(Environment.Newline,
> Directory.GetFiles([start point], "*.*", SearchOption.AllDirectories)))
>
>
Well done Stephany! That is one of the simplest, yet at the same time
most functional, solution I've ever seen to the OP problem. That's what
can make these NG's such a special resource.

ShaneO

There are 10 kinds of people - Those who understand Binary and those who
don't.

2003?@discussions.microsoft.com vs 2003?

unread,
Oct 20, 2006, 8:46:01 PM10/20/06
to
Works great for me in VS2005. Should this code work with .net 1.1 I cannot
seem to get it to... perhaps you know what I'm doing wrong.. of it it can
work at all?

Thanks!

Stephany Young

unread,
Oct 21, 2006, 12:14:21 AM10/21/06
to
The technique demonstrated uses features introduced in .NET Framework 2.0.


"vs 2003?" <vs 2003?@discussions.microsoft.com> wrote in message
news:9F3BDDC2-D1E3-4624...@microsoft.com...

0 new messages