R
RML
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[]
--------------------------------------------------------------------------------------------------------------
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[]
--------------------------------------------------------------------------------------------------------------