In a personal video database, I would like to be able to transfer a video to another media (eg. external hard drive) just by clicking a dedicated button within a form.
My issue is on the file copy process within the macro. I’ve found 3 different ways to proceed:
- FileCopy statement, which is operating very well
- File I/O Functions, with opening source and target files, get from source and put to target, then closing file
- SimpleAccessFile procedures (see section 8.9.3 in Pitonyak’s book OpenOffice.org Macros Explained) with streams, readBytes() and writeBytes() functions.
All of 3 solutions work. However :
- Solution 1 is really very very faster (at least in my tries) but as a “single-time” process, it seems that nothing else could be done until the copying is ended
- Solutions 2 and 3 are very very slow, but as either bits or bundles of bits are copied at a time, it is possible to process another action after each bit/bundle transfer.
Actually, I was looking for such a solution (like Solutions 2 and 3), as I would like to display a progress bar during the transfer, and refresh it with the right percentage/bar advancement. But given the so long time transfer with Solutions 2 and 3, it is not convenient at all (for movie files of several 100 Go…).
So my questions are:
- is it possible to stop/pause the FileCopy process (in order to actualize the progress bar)?
- and/or is it possible to speed up (boost) the Solutions 2 or 3?
For information, I provide in the following my Sub code for the above mentioned solutions (it’s the first time I used these processes, so my approach may be not accurate…):
Sub FileCopyTransfer sSource = "/myVideo.mp4" sTarget = "/myVideo2.mp4" FileCopy(sSource,sTarget) End Sub
Sub IOTransfer sSource = "/myVideo.mp4" sTarget = "/myVideo2.mp4" nS = Freefile Open sSource For Binary Access Read As nS nT = FreeFile Open sTarget For Binary As nT Dim v as Long location = Loc(nS) While Not Eof(nS) Get nS, location+1, v Put nT,,v location = Loc(nS) Wend Close nS Close nT End Sub
Sub SimpleFileAccessTransfer ' SimpleFileAccess service' Dim sFileName$ ' Name of file to open' Dim oStream ' Stream returned from SimpleFileAccess' Dim oMyStream ' Stream service' sFileSource = "/myVideo.mp4" sFileTarget = "/myVideo2.mp4" ' Create the SimpleFileAccess service' oSFASource = CreateUnoService("com.sun.star.ucb.SimpleFileAccess") oSFATarget = CreateUnoService("com.sun.star.ucb.SimpleFileAccess") ' Create the Specialized source (input) and target (output) streams' oMyStreamSource = CreateUnoService("com.sun.star.io.DataInputStream") oMyStreamTarget = CreateUnoService("com.sun.star.io.DataOutputStream") ' Open the source file for reading and target file for writing' oStreamSource = oSFASource.openFileRead(sFileSource) oStreamTarget = oSFATarget.openFileWrite(sFileTarget) ' Connect the source file to input stream and target file to output stream' oMyStreamSource.setInputStream(oStreamSource) oMyStreamTarget.setOutputStream(oStreamTarget) ' Define bits block to work with (1/10 of file size) and variable to store them' nb = Int(oStreamSource.Length/10)+1 Dim Bundle() As Long While oMyStreamSource.InputStream.Position < oStreamSource.Length oMyStreamSource.readBytes(Bundle(),nb) oMyStreamTarget.writeBytes(Bundle()) Wend End Sub
Thanks for any idea!