i am trying to get list of files inside the directory in this case "c:\dir\" (ofcourse i have files inside) and i wanted to display the name of those files in console program build in c#....
initially i did this....
static class Program
{
static void Main()
{
string[] filePaths = Directory.GetFiles(@"c:\dir\");
Console.WriteLine();
Console.Read();
}
}
how can i see the name of those files....... any help would be appreciated.....
thank you.
(further i would like to know if possible any idea on sending those file path towards dynamic html page.... any general concept how to do that...)
If by "file names" you mean literally just the names and not the full paths:
string[] filePaths = Directory.GetFiles(@"c:\dir");
for (int i = 0; i < filePaths.Length; ++i) {
string path = filePaths[i];
Console.WriteLine(System.IO.Path.GetFileName(path));
}
Loop through the files and print them one at a time:
foreach(string folder in Directory.GetDirectories(@"C:\dir"))
{
Console.WriteLine(folder);
}
foreach(string file in Directory.GetFiles(@"C:\dir"))
{
Console.WriteLine(file);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With