Hello together,
I searched for a possiblity to copy a whole directory on every platform supported by Lazarus. Thanks to
Leledumbo, I found a way to get this working. Maybe there're some guys outside who still search for this, so I publish my work here
.
I created an simple and easy class, called "TCopyDir", which uses TFileSearcher to enumerate an entire directory and copy its content file by file.
Example Code:
procedure TfrmMain.btCopyClick(Sender: TObject);
var
CopyDir: TCopyDir;
Log: TStringList;
begin
CopyDir := TCopyDir.Create('C:\', 'D:\');
CopyDir.Start;
Log := CopyDir.GetLog;
CopyDir.Free;
end;
As you can see, the class is very simple to use and contains a log (TStringList). In this example, the whole content of "C:\" would be copied to "D:\".
[EDIT 2013-06-23
]As of 23.06.2013, there's a improved version of TCopyDir (called TCopyDir v2). For more details see
here[/EDIT][EDIT 2013-08-10
]onivan found a bug in TCopyDir and has already created a fix. Make sure to read
his post.
[/EDIT][EDIT 2014-01-06
]Caladan found
another bug in TCopyDir
affecting Unix users only. See
this post for a fix!
[/EDIT][EDIT2014-06-03
]I uploaded version 2.1 of TCopyDir which fixes two above mentioned bugs, plus I changed the disclaimer!
[/EDIT]Download and example application in the attachments.
My work is Free Domain but remain the terms of LCL!
With the use of this work you agree to the following:
THIS SOFTWARE IS PROVIDED BY BASTLA "AS IS" AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL BASTLA BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
I hope this is useful for some of you!
Greetings,
bastla