How do you get the file size in C#?

2019-01-05 02:15发布

I need a way to get the size of a file using C#, and not the size on disk. How is this possible?

Currently I have this loop

foreach (FileInfo file in downloadedMessageInfo.GetFiles())
{
    //file.Length (will this work)
}

Will this return the size or the size on disk?

标签: c# filesize
7条回答
手持菜刀,她持情操
2楼-- · 2019-01-05 03:13

If you have already a file path as input, this is the code you need:

long length = new System.IO.FileInfo(path).Length;
查看更多
登录 后发表回答