C sharp file size in bytes
Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. How do you get the file size in C? Ask Question. Asked 12 years, 4 months ago. Active 1 year, 7 months ago. Viewed k times. I need a way to get the size of a file using C , and not the size on disk.
How is this possible? Improve this question. Peter Mortensen Related, but for VB. NET , — Peter Mortensen. Add a comment. Active Oldest Votes. FileInfo path. Improve this answer. Luca Cremonesi 2 2 gold badges 3 3 silver badges 13 13 bronze badges. Also: social. There is no method "FileInfo. Real answer is new FileInfo path. Length what can be heavy for mass operation. Length is how the doc refers to the property, even though it is not static.
The answer is relative to the code in question. Viewed 3k times. Improve this question. EnibMoc EnibMoc 1 1 silver badge 4 4 bronze badges. Add a comment. Active Oldest Votes. Improve this answer. Sylvain Defresne Sylvain Defresne I'm overwhelmed by the number of responses and the response time. SO is marvelous! EnibMoc You could also use long long or its unsigned partner, which are guaranteed to be at least 64 bits. Paul R Paul R k 33 33 gold badges silver badges bronze badges.
Nick Shaw Nick Shaw 2, 19 19 silver badges 27 27 bronze badges. It is not an unsigned int , it is an unsigned integral type. Apologies, paxdiablo, it's actually platform dependent as you imply. On Windows using bit it's equivalent to an unsigned int. Last time I trust what Visual Studio tells me. More info here: en. OK, and pass it to the method above.
The following Windows Forms example shows how this is done. Tip: This site contains a useful tutorial on the FolderBrowserDialog control, which can help with getting this working. Directory size. A method can calculate the total size of a directory. It considers each file. It returns the total bytes of all files. This is useful for compression or file transfers. We determine the size of a directory. We can use the Directory class and a foreach-loop.
NET Framework does not provide one method to determine the directory size. We must write our own custom method. Here we sum the length of each file, returning the total size in bytes. Static Array Step 2: The prorgram loops over each file.
0コメント