Click here to Skip to main content
16,016,568 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to calculate progress for fileStream.SetLength?
I need it, because i use it on a FlashDrive and it takes a time.
Posted
Updated 6-Apr-10 23:38pm
v2

Hi,
This is a follow on from the question you asked recently.

http://www.codeproject.com/answers/70212/How-to-reserve-space-for-a-file-like-Explorer-does.aspx[^]

You have probably found out from your own experiments that SetLength is physically clearing the allocated space on the drive and this does take time, in fact it takes exactly the same time as if you were to write a file of the same length. Getting progress reports is not possible as SetLength does not return until this process is complete.

One of the answers to your previous post suggested writing a file of the correct size and of course if you were to do this you would be able to generate progress reports giving percent completion.

You may be unaware that NTFS formatted drives have an optimisation which allows SetLength to return almost immediately, often within about 10ms, although the allocated space cannot actually have been cleared in that time.

My suggestion is
1) Detect the drive format (System.IO.DriveInfo)
2) If it's NTFS use SetLength which will be very fast
3) For any other format, write a file of the desired length and generate you own progress reports.


Alan.
 
Share this answer
 
v2
FileStream.SetLength sets the length of the file stream and that is all. What do you mean by calculate progress? What are you trying to do.

-Saurabh
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900