hello,
i want to know how can i copy a file in a way if it was stopped for a reason
it can continue from the last point just like what torrents and file
download managers do?
thanks..
Stanimir Stoyanov - 31 Aug 2007 16:00 GMT
> i want to know how can i copy a file in a way if it was stopped for a
> reason it can continue from the last point just like what torrents and
> file download managers do?
Hello Jassim,
This could be done in various ways but the most straightforward one is to
have a FileStream [1] instance of your target file, write data to it from
the source and close the Stream when necessary. To resume, open the
FileStream again and seek to the last written byte and continue transferring
data. You can make use of the Position and Length properties or the Seek
method of the FileStream class.
[1] http://msdn2.microsoft.com/en-us/library/system.io.filestream.aspx
Best Regards,
Stanimir Stoyanov
www.stoyanoff.info | www.aeroxp.org
Peter Duniho - 31 Aug 2007 17:45 GMT
> hello,
>
> i want to know how can i copy a file in a way if it was stopped for a
> reason it can continue from the last point just like what torrents and
> file download managers do?
It depends on how you are copying the file. The shell doesn't provide a
built-in way to do this, AFAIK. But if you are writing your own copy
code (which is simple enough), it should be a simple matter to look at
the file length of the destination, and use that to determine where to
resume copying. Just open the destination file for appending, and seek
in the source file to the length of the destination file before you
start reading.
Pete
Ignacio Machin ( .NET/ C# MVP ) - 31 Aug 2007 19:00 GMT
Hi,
>> hello,
>>
[quoted text clipped - 9 lines]
> source file to the length of the destination file before you start
> reading.
In addition you should verify that the source file is the same that the file
you were copying the first time.
Peter Duniho - 31 Aug 2007 19:11 GMT
> In addition you should verify that the source file is the same that the file
> you were copying the first time.
Heh...well, there's a whole host of things I left out, all related to
the above (the question of whether the source file is the same is a
whole thread unto itself). I was just discussing the "how to resume"
aspect, not the "whether to resume".
But yes I agree, one should verify that resuming the copy is the right
thing to do before actually resuming it.
Pete