|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Find Files and folderswhat 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? "frogman7" <frogm***@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 How are you writing out to the file? > loops and it extremely slow. Is there a function that grabs all the > files from a folder and subdirectories? Are you concatenating the data before outputting? 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 frogman7 wrote:
> I am using streamwriter at present. as i loop through and find the How are you obtaining the directory information? That was the source> 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 of slowdown when I tried something similar recently. 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? frogman7 wrote:
> I basically get the top directory and find all the files in that Actually, I meant what method or commands you were using to get the> 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? 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 Sorry I didn't understand
I am using the system.IO.getfiles and getdirectories I will look at your post and try it. thanks 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))) Show quoteHide quote "frogman7" <frogm***@googlemail.com> wrote in message news:1160804935.702168.138180@i3g2000cwc.googlegroups.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 > Stephany Young wrote:
> File.WriteAllText([output filename], String.Join(Environment.Newline, Wow, that's beautiful. :)> Directory.GetFiles([start point], "*.*", SearchOption.AllDirectories))) 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. 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! Show quoteHide quote "tesla***@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. > > The technique demonstrated uses features introduced in .NET Framework 2.0.
Show quoteHide quote "vs 2003?" <vs 20***@discussions.microsoft.com> wrote in message news:9F3BDDC2-D1E3-4624-8AA9-220BFF5C3F3C@microsoft.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! > > "tesla***@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. >> >> Stephany Young wrote:
> Well done Stephany! That is one of the simplest, yet at the same time > In it's simplest terms it becomes: > > File.WriteAllText([output filename], String.Join(Environment.Newline, > Directory.GetFiles([start point], "*.*", SearchOption.AllDirectories))) > > 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.
Prevent form minimize
Threading a ShowDialog? - progress form. is there any way to find the position of mouse click on a form dialog to choose folder in vb .net 2005 Minimizing the Console Window reversing the Mod operator CopyMemory(buffer, newBuffer, nBytes)? How To Redistribute Office 2003 DLLS .net framework 1.1.4322 Datagridview and arraylist |
|||||||||||||||||||||||