Recent

Author Topic: Copying an entire directory (incl. subdirectories)  (Read 30538 times)

bastla

  • New Member
  • *
  • Posts: 23
Re: Copying an entire directory (incl. subdirectories)
« Reply #15 on: August 10, 2013, 08:56:38 pm »
Thanks!
I added a small note to the start post, hopefully everybody will notice your post.

Caladan

  • Newbie
  • Posts: 5
Re: Copying an entire directory (incl. subdirectories)
« Reply #16 on: January 03, 2014, 06:36:36 pm »
this is so close to what I been looking for, thank you !

1 error in the source though

line 278
{$IFDEF Unix} self._copyAttributes := false;
    {$ELSE} self._preserveAttributes := true {$ENDIF};

assume that should be _preseriveAttributes on the 1st line.

also it does not copy all file atributes under linux, for example tis not copying the executable flag, will see if I can find a solution for that.

bastla

  • New Member
  • *
  • Posts: 23
Re: Copying an entire directory (incl. subdirectories)
« Reply #17 on: January 05, 2014, 01:13:37 pm »
Hi Caladan,

yes, your're right, it should be
Code: [Select]
  {$IFDEF Unix} self._preserveAttributes := false; in line 278. I'm sorry for that error! May I link your post to the start post so that everybody will see the bug?

Unfortunately, I'm not an excessive Linux user, so I don't know much about coding on Linux. That's why I can't figure out how to handle file attributes on Linux. It would be great if you could find a solution on how to read and set all those file attributes!

Greetings,
bastla

Caladan

  • Newbie
  • Posts: 5
Re: Copying an entire directory (incl. subdirectories)
« Reply #18 on: January 05, 2014, 01:29:43 pm »
feel free to link.

Well with fpchmod you can set the correct attributes but I have yet to find a way to get them from the original file.... so far unlucky to find a command or way to get them.

bastla

  • New Member
  • *
  • Posts: 23
Re: Copying an entire directory (incl. subdirectories)
« Reply #19 on: June 03, 2014, 09:50:06 pm »
Time to push this once again! :D
I uploaded a new version fixing bugs found by onivan and Caladan! Thank you very much!

Cheers,
bastla

aducom

  • Full Member
  • ***
  • Posts: 155
    • http://www.aducom.com
Re: Copying an entire directory (incl. subdirectories)
« Reply #20 on: April 05, 2015, 09:26:27 am »
Only one remark, the class is using TList as an array of string. If you have a TList in your application than that might interfere. Just change it to TListString and no conflicts any more. I know this is an old post, but a very useful one.

nogo

  • Newbie
  • Posts: 5
Re: Copying an entire directory (incl. subdirectories)
« Reply #21 on: July 30, 2015, 01:57:08 pm »
For me copying of files in a hidden folder does not work on Windows

kind regards,

nogo

AlexTP

  • Hero Member
  • *****
  • Posts: 2386
    • UVviewsoft
Re: Copying an entire directory (incl. subdirectories)
« Reply #22 on: August 15, 2015, 01:12:30 pm »
Used in CudaText now. Thax... (note: I made error and wrote srcdir==todir, and unit created empty dir. better check SameFilename (Win32 aware) and don't do.)

eac

  • Newbie
  • Posts: 1
Re: Copying an entire directory (incl. subdirectories)
« Reply #23 on: August 23, 2015, 08:53:09 pm »
Excellent job here, indeed!  :)

But I have a newbie question.
How could I do to keep the creation date of the files?
Because putting
CopyDir.PreserverFileDates := true;
wasn't helpful for me :(

Thanx!

AlexTP

  • Hero Member
  • *****
  • Posts: 2386
    • UVviewsoft
Re: Copying an entire directory (incl. subdirectories)
« Reply #24 on: October 30, 2015, 07:26:53 am »
Please: feature-request

I want to copy folder A to B but only those files in A, which don't exist in B or newer than files in B-
ie, I need option "CopyOnlyNewerFiles" - can you add, pls?

AlexTP

  • Hero Member
  • *****
  • Posts: 2386
    • UVviewsoft
Re: Copying an entire directory (incl. subdirectories)
« Reply #25 on: June 09, 2020, 12:57:58 am »
My fork, some changes
- some LCL usual type was redefined??? bad. fixed to TDirsArray
- "const" string params
- removed too much logging

https://github.com/Alexey-T/CudaText/blob/master/comp/copydir.pas

CM630

  • Hero Member
  • *****
  • Posts: 1082
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: Copying an entire directory (incl. subdirectories)
« Reply #26 on: January 20, 2022, 11:19:54 am »
...
https://github.com/Alexey-T/CudaText/blob/master/comp/copydir.pas
This URL is dead.

I tried to use TCopyDir v2-1 by bastla.zip, in a console app, but it does not seem to understand self.....
« Last Edit: January 20, 2022, 11:36:03 am by CM630 »
Лазар 3,2 32 bit (sometimes 64 bit); FPC3,2,2; rev: Lazarus_3_0 on Win10 64bit.

Thaddy

  • Hero Member
  • *****
  • Posts: 14213
  • Probably until I exterminate Putin.
Re: Copying an entire directory (incl. subdirectories)
« Reply #27 on: January 20, 2022, 11:52:41 am »
https://swissdelphicenter.ch/en/showcode.php?id=152 Windows only. Old but still works.
Specialize a type, not a var.

AlexTP

  • Hero Member
  • *****
  • Posts: 2386
    • UVviewsoft
Re: Copying an entire directory (incl. subdirectories)
« Reply #28 on: January 20, 2022, 01:28:58 pm »
Old code from CudaText repo is now stored in own repo. Enjoy.
https://github.com/Alexey-T/CopyDir-Lazarus

Quote
*                               TCOPYDIR
*                               ========
*                                 v2.1
*
*  This unit contains "TCopyDir" class wich copies entire directories (incl. its
*  subdirectories)
*
*  Author: bastla (@ Supernature-Forum / @ Lazarus Forum)
*  License: Free Domain
*
*  How TCopyDir works:
*  -------------------
*  TCopyDir uses TFileSearcher to enumerate a whole directory and copies its
*  content file by file.
*  Because of using LCL-components only, this class should work on all available
*  platforms supported by Lazarus and LCL.

CM630

  • Hero Member
  • *****
  • Posts: 1082
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: Copying an entire directory (incl. subdirectories)
« Reply #29 on: January 24, 2022, 12:29:53 pm »
I noticed GetTickCount in the code. This line: self._AddToLog('COPYING DONE (in ' + IntToStr(GetTickCount - __startTime) +  ' ms)');
might show nonsense.
Лазар 3,2 32 bit (sometimes 64 bit); FPC3,2,2; rev: Lazarus_3_0 on Win10 64bit.

 

TinyPortal © 2005-2018