File size

TechnoTone

Well-known member
Joined
Jan 20, 2003
Messages
224
Location
UK - London
I am trying to get the size of a file. I am using the Open method of the File class to get a FileStream object and using the Length property which is working fine when the file is accessible. However, most of the time the file will be open by another program. Ive also tried to open the file using OpenRead and that still doesnt work.

How can I get the size of a file without actually opening it?


PS. The strange thing is that when I attempt to open a file that is in use by another pogram an exception doesnt occur. I just get nothing returned instead of a FileStream object. I would have thought an exception would be raised.
 
Use the FileInfo class;

Code:
Dim info As New FileInfo(path)
Dim fileSize As Long = info.Length

C#:
FileInfo info = new FileInfo(path);
long fileSize = info.Length;
 

Similar threads

Back
Top