Re: list files in subdirectory trouble!! please look at this snippet

From: Nick Malik [Microsoft] (nickmalik_at_hotmail.nospam.com)
Date: 02/02/05


Date: Tue, 1 Feb 2005 22:49:49 -0800

because this line is not good:

           foreach (DirectoryInfo diNext in dirs)
            {
                Console.WriteLine(diNext.GetFiles("*.doc"));
            }

diNext.GetFiles() will return an array of files that matches the expression.
How do you want .net to create a string that "represents" a reference to an
array?

The default way to do this is to print out the type, which is what you are
getting. If you want to print out the actual contents, then you will need
an inner loop to scan through the array, get the file names, and print them
out.

-- 
--- Nick Malik [Microsoft]
    MCSD, CFPS, Certified Scrummaster
    http://blogs.msdn.com/nickmalik
Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
   I do not answer questions on behalf of my employer.  I'm just a
programmer helping programmers.
--
"RML" <rml@robertlyon.com.au> wrote in message
news:uzBaP4OCFHA.3368@TK2MSFTNGP10.phx.gbl...
> hey guys,
>
> i am looking at this piece of code that lists numbers of files in a
> directory. i want to convert it so it lists the files in th directory that
> end with .doc. i cant seem to get it to output correctly, i have included
> the original code, my modified code, and the output from my modifed code..
> why does it list the files as "System.IO.FileInfo[]"???
>
> thanks
>
> --------------------------------------------------------------------------
------------------------------------
> ORIGINAL C# CODE
> --------------------------------------------------------------------------
------------------------------------
>
> using System;
> using System.IO;
>
> class Test
> {
>     public static void Main()
>     {
>         try
>         {
>             DirectoryInfo di = new DirectoryInfo(@"c:\");
>
>             // Get only subdirectories that contain the letter "p."
>             DirectoryInfo[] dirs = di.GetDirectories("*p*");
>
>             Console.WriteLine("Number of directories with a p: {0}",
> dirs.Length);
>
>             // Count all the files in each subdirectory that contain the
> letter "e."
>             foreach (DirectoryInfo diNext in dirs)
>             {
>                 Console.WriteLine("The number of files in {0} with an e is
> {1}", diNext,
>                     diNext.GetFiles("*e*").Length);
>             }
>         }
>         catch (Exception e)
>         {
>             Console.WriteLine("The process failed: {0}", e.ToString());
>         }
>     }
> }
>
> --------------------------------------------------------------------------
------------------------------------
>
> --------------------------------------------------------------------------
------------------------------------
> MY MODIFICATIONS
> --------------------------------------------------------------------------
------------------------------------
> using System;
> using System.IO;
>
> class Test
> {
>     public static void Main()
>     {
>         try
>         {
>             DirectoryInfo di = new DirectoryInfo(@"h:\");
>
>             // Get Subdirectories
>             DirectoryInfo[] dirs = di.GetDirectories();
>
>             Console.WriteLine("Number of directories is {0}",
dirs.Length);
>
>             // Count all the files in each subdirectory that contain the
> letter "e."
>             foreach (DirectoryInfo diNext in dirs)
>             {
>                 Console.WriteLine(diNext.GetFiles("*.doc"));
>             }
>         }
>         catch (Exception e)
>         {
>             Console.WriteLine("The process failed: {0}", e.ToString());
>         }
>     }
> }
>
>
> --------------------------------------------------------------------------
------------------------------------
>
> --------------------------------------------------------------------------
------------------------------------
> THE OUTPUT
> --------------------------------------------------------------------------
------------------------------------
> Number of directories is 4
> System.IO.FileInfo[]
> System.IO.FileInfo[]
> System.IO.FileInfo[]
> System.IO.FileInfo[]
> --------------------------------------------------------------------------
------------------------------------
>
>


Relevant Pages

  • Re: garbage collection problem in large linked lists
    ... Instead all buckets are allocated at once in an array. ... VG.net, which must be very scalable, but only for lists which would normally ... Linked lists require pointer dereferencing in order to traverse. ... When you run out of space, you allocate a new smaller array. ...
    (microsoft.public.dotnet.framework.performance)
  • Re: Dict sharing vs. duplication
    ... array to enforce unique keys and I use lists to enforce order. ... API in a page or two of Tcl code, it isn't so much a missing feature ... OpenACS database API which creates a new specialized data structure, ...
    (comp.lang.tcl)
  • Re: Translating python to scheme
    ... Scheme has mutation, and there are reasons to use it. ... confusing when considering a 2d array. ... in other languages: Lisp Lists and Vectors. ...
    (comp.lang.scheme)
  • Re: Compare the values of two sorted arrays of variable size.
    ... This algorithm does not check for every possible location in each array. ... > contains a double loop where each element of the inner loop is compared ... > Dim lngMaxAIdx ' Upper value of the A list index. ... one of the lists has finished. ...
    (microsoft.public.scripting.vbscript)
  • Re: Approx mode creates largedr matricies
    ... real/complex "array" types ... In the "list (of lists)" alternate storage type, ... no ROM address is ever used, ... which started with the HP48S series) ...
    (comp.sys.hp48)