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?