file copy question

  • Thread starter Thread starter Jassim Rahma
  • Start date Start date
J

Jassim Rahma

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..
 
Jassim Rahma said:
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
 
Jassim said:
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
 
Hi,

Peter Duniho said:
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.

In addition you should verify that the source file is the same that the file
you were copying the first time.
 
Ignacio said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top