473,382 Members | 1,447 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Find Files and folders

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?

Oct 13 '06 #1
11 2474
"frogman7" <fr******@googlemail.comwrote 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?
Oct 13 '06 #2
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

Oct 13 '06 #3
frogman7 wrote:
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
How are you obtaining the directory information? That was the source
of slowdown when I tried something similar recently.

Oct 13 '06 #4
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?

Oct 13 '06 #5

frogman7 wrote:
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?
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/micro...62e68f40049cc4

Oct 14 '06 #6
Sorry I didn't understand

I am using the system.IO.getfiles and getdirectories

I will look at your post and try it.

thanks

Oct 14 '06 #7
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" <fr******@googlemail.comwrote in message
news:11**********************@i3g2000cwc.googlegro ups.com...
Sorry I didn't understand

I am using the system.IO.getfiles and getdirectories

I will look at your post and try it.

thanks

Oct 14 '06 #8
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.

Oct 14 '06 #9
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.
Oct 14 '06 #10
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!

"te******@hotmail.com" wrote:
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.

Oct 21 '06 #11
The technique demonstrated uses features introduced in .NET Framework 2.0.
"vs 2003?" <vs 20***@discussions.microsoft.comwrote in message
news:9F**********************************@microsof t.com...
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!

"te******@hotmail.com" wrote:
>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.


Oct 21 '06 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Robert Magnusson | last post by:
Hi All, This is sure to be an easy question. I am wondering what the accepted standard is for referencing a sub-folder below the application.exe folder? In VB6 you simply used App.Path and...
2
by: Glen | last post by:
As I understand it, when the first page of an application is accessed, all ASPX/ASCX/etc. files in the same folder are compiled using the JIT compiler. Is there a way to turn this feature off? ...
1
NarenMCA
by: NarenMCA | last post by:
Hi, The below code in MS Outlook gives me the names of folders in "public folders". I am looking forward to get all the subfolders and files in "Public folders" Please assist me in this. ...
4
by: jonathan184 | last post by:
Hi I have a perl script, basically what it is suppose to do is check a folder with files. Now the files are checked using a timestamp with the command ls -l so the timestamp in this format is...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.