Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9017887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:23:03+00:00 2026-06-16T04:23:03+00:00

Possible Duplicate: Get Size of file on disk Is there a way to retrieve

  • 0

Possible Duplicate:
Get Size of file on disk

Is there a way to retrieve the actual number of bytes used for a particular file on disk, using C# / windows?

My application implements “watch” folders, similar to FileSystemWatcher. Some watch folders exist on shared storage (both network and fibre channel SAN), others on locally attached storage.

Files are copied into a watch folder by processes that are completely out of my control, sized anywhere from 1 GB to > 500 GB. Because of the nature of shared file systems, hoping for an exception when opening files “exclusively” (FileMode.Open, FileAccess.Read, FileShare.None) doesn’t work either.

These watch folders are not supposed to take action until a file is completely copied/closed – otherwise problems downstream can occur.

To get the “real” file size used on disk I have tried:

  • System.IO.FileInfo
  • GetFileSizeEx (kernel32 p/invoke)
  • FindFirstFileEx (kernel32 p/invoke)
  • GetCompressedFileSize & GetDiskFreeSpace (kernel32 p/invoke)

Any suggestions would be very much appreciated. It seems like I’m dealing with a limitation of the Windows OS?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T04:23:04+00:00Added an answer on June 16, 2026 at 4:23 am

    To summarize, the issue here is that the other applications copy the file by creating the destination, then using SetFileSize to set the file size to the final size (let’s say 1GB), essentially creating a 1GB file filled completely with zeroes.

    The applications then seek back to the beginning of the file and start filling it sequentially with data. The goal is to determine what point in the “filling it with data” the other applications have reached.

    The unfortunate answer is that there is no way to obtain this information. As far as the file system is concerned, the file exists and its size is 1GB. it so happens that the file is being actively updated without changing the size, but those internal changes are not audited in file metadata. There is no “last modified time” for individual bytes of a file.

    If you have domain-specific knowledge of the files (e.g. you know that the last byte is never zero) you can poll the last byte of the file and back off if it is zero.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: programatically get the file size from a remote file using delphi, before
Possible Duplicate: Is there any way to get the size of a c function?
Possible Duplicate: Get variable name. javascript “reflection” Is there a way to know the
Possible Duplicate: get jquery to return font-size in points Using jQuery, I'm setting something
Possible Duplicate: Easiest way to get file's contents in C My program reads files
Possible Duplicate: How to get the file size given a path? I am trying
Possible Duplicate: Size of folder or file I used this code to instantiate a
Possible Duplicate: Get file name from URI string in C# How to extract file
Possible Duplicate: Get the resolution of a jpeg image using C# and the .NET
Possible Duplicate: Get the IP Address of local computer Obtaining local IP address using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.