3

To find out the length of a file (in bytes) you would normally use FileInfo.Length or System.IO.Stream.Length (is there a difference?). Both are of type long, i.e. System.Int64, hence the maximal possible value is:

9 223 372 036 854 775 807

Now it seems some filesystems, such as NTFS5 or Microsoft's Resilient File System (ReFS) theoretically allow a maximum file size that exceeds the Int64 range - according to this source, ReFS limits maximal file size to 2^64-1 bytes, which equals to (for readability purposes):

18 446 744 073 709 551 615

How would one go about determining file size in such case - however hypothetical it may be - and would it impact normal Stream operations (such as using Read/Write methods etc.)?

w128
  • 4,680
  • 7
  • 42
  • 65
  • no one has a file that big.... – Mitch Wheat May 16 '13 at 10:38
  • Use an unsigned 64-bit integer? – John Willemse May 16 '13 at 10:38
  • 3
    I've seen some pretty large numbers here at Google for "total storage sizes" etc... but I don't think it would become a realistic concern even here. – Jon Skeet May 16 '13 at 10:39
  • 1
    With the current hardware, it is impossible to create a file that big, but when that time comes, Microsoft will add an extra property to the .NET framework (if it still exists at that point) for your grandchildren that returns a `BitInteger`. – Steven May 16 '13 at 10:40
  • @MitchWheat, suppose that I for whatever reason append together multiple disk images. The question is meant to be purely hypothetical. John Willemse that was my first thought, thanks; but what is the reason that .NET operates with long instead of ulong in the first place? – w128 May 16 '13 at 10:40
  • 3
    if it's not a problem for google, then you are wasting your time asking. – Mitch Wheat May 16 '13 at 10:42
  • @MitchWheat but I cannot know a priori if it's a problem for google or not, so condescending comments like this absolutely do not help. I think it's a fair question to ask. – w128 May 16 '13 at 10:46
  • 1
    @MitchWheat, I would not agree. The question is related to the .NET circle, and google is not addressing these technologies. For the sake of curiosity, I am sure there will be people (including myself) who want to know the alternatives in such even hypothetical scenario. – Ivaylo Slavov May 16 '13 at 10:46
  • Let me know when you have a file even 1/1000 that size.... – Mitch Wheat May 16 '13 at 10:47
  • 2
    They operate with long, because there's no need for anything else _right now_ or the foreseeable future. – John Willemse May 16 '13 at 10:51
  • 1
    @MitchWheat, it is not about of ever reaching it, it is the desire of knowing how to handle such case. I am sure this can be answered regardless of the possibility for practical occurence – Ivaylo Slavov May 16 '13 at 10:51
  • 1
    @MitchWheat That's why it's called a hypothetical/theoretical question. Last I checked, it was ok to ask questions that may not have direct practical value here. No need to be antagonizing. – w128 May 16 '13 at 10:51
  • 1
    Let's say you used terrabyte standard size hard drives, and your file spanned multiple drives... You'd need >8000 cubic meters of harddrive, and that's even without cabling and supporting interfaces! – spender May 16 '13 at 10:51
  • @MitchWheat a better question would be _why_ they wouldn't make better programmers.. and even then, some synthetic neurobiologists may have a thing or two to say, even if not pragmatic at the time. – w128 May 16 '13 at 11:00
  • @MitchWheat, I am sure we are all going to be a better programmers if we ask hypothetical questions and struggle for the answer (I don't mean post them all here). I am sure you did that many times yourself walking the path to become a developer. Back then, there might not have been a stackoverflow site to ask on, this does not mean you should not ask. If you do not want to know about > int64 file-sizes, do not stop others from wanting. The ones who ask hypothetical questions are those most likely to give an answer one day. – Ivaylo Slavov May 16 '13 at 11:10

1 Answers1

4

How would one go about determining file size in such case

There's nothing built-in to the .NET framework. When your file gets bigger, both FileInfo.Length and System.IO.Stream.Length will throw an exception. You will have to fall back to calling the Windows API directly (if the Windows API supports this currently).

Steven
  • 166,672
  • 24
  • 332
  • 435