Reputation: 37
I want to list all the files and all its properties (name,size,etc) in a directory but i only managed to get the names of the files. here's the code
<table>
@foreach(var fileName in Directory.GetFiles("C:/baba"))
{
<tr><td>@Path.GetFileName(fileName)</td></tr>
}
</table>
Upvotes: 1
Views: 63
Reputation: 4848
Perhaps something like this:
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
var dir = new DirectoryInfo(@"C:\Windows");
foreach (var file in dir.GetFiles())
{
Console.WriteLine("Name: " + file.Name + "\r\nSize: " + file.Length + "\r\nType: " + file.GetType());
}
Console.ReadKey();
}
}
}
Gives the following output:
Upvotes: 0
Reputation: 24078
Use the DirectoryInfo
class instead. It returns an object instead of a string and it contains more information. The equivalent method would be DirectoryInfo.GetFiles
.
Upvotes: 2