2

I am writing lots of files using c#. File size is 1 mb and about 500 files are there in the folder.All the files are written properly with all of their contents. But some files are showing file size zero in windows explorer even though it has contents.

I can see size when I copy the files to other location. Also I can see size when i open in the same location and refresh the windows explorer.

tony montana
  • 105
  • 1
  • 13

1 Answers1

0

This is propably a caching problem in Windows Explorer. It measured the filesize when your program created the new file, but before any content has been written to it. Now it is showing the wrong (outdated) value. If you can open the file and see the content, everything worked fine.

Try to refresh the folder in Windows Explorer with F5 or try it again after some time.

You can also open the console (cmd), go to your target folder (cd path) and take a look at the correct filesize using the command dir.

maja
  • 17,250
  • 17
  • 82
  • 125
  • I refreshed and I am sure about the working of my code -all contents are fine. This is only for user not to be misleaded – tony montana Apr 29 '15 at 12:53
  • Same situation. NLog, for example appends to a log file and you can see in Windows Explorer its filesize grow by the second. Using a BinaryWriter over a FileStream and even calling .Flush on both objects, I don't see a size increase. – Micah Epps Jul 31 '20 at 18:40