I want to get the size to show in the ListView. But my code return 0. I find.Length() get length size but only have Count() and it can't resolve my problem.
My code like:
string[] filePaths = (string[])e.Data.GetData(DataFormats.FileDrop, false);
List<FileInfo> fileInfos = new List<FileInfo>();
foreach (string filePath in filePaths)
{
FileInfo f = new FileInfo(filePath);
fileInfos.Add(f);
long s1 = fileInfos.Count;
string chkExt = Path.GetExtension(f.ToString());
s1 = s1/1024;
decimal d = default(decimal);
d = decimal.Round(s1, 2, MidpointRounding.AwayFromZero);
// d is 0. Because s1 = 1 only count not length of file.
You are using fileInfos
, which is a List<T>
. You want to check the length of your actual FileInfo f
:
long s1 = f.Length;
While you are dividing by 1024, please note, that there is a difference in units when dealing with filezises, depending on your base: 2 or 10. KB is 2^x and kB is 10^x bytes.
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