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?
Click the file or folder. Press Command + I on your keyboard. A window opens and shows the size of the file or folder.
ftell() in C This function is used to get the total size of file after moving the file pointer at the end of the file. It returns the current position in long type and file can have more than 32767 bytes of data.
format("The size of the file: %d bytes", fileSize); These methods will output the size in Bytes. So to get the MB size, you need to divide the file size from (1024*1024).
The best Linux command to check file size is using du command. What we need is to open the terminal and type du -sh file name in the prompt. The file size will be listed on the first column. The size will be displayed in Human Readable Format.
If you have already a file path as input, this is the code you need:
long length = new System.IO.FileInfo(path).Length;
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