Recent

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

Zvoni

  • Hero Member
  • *****
  • Posts: 1182
Re: Copying an entire directory (incl. subdirectories)
« Reply #30 on: January 24, 2022, 12:50:08 pm »
https://swissdelphicenter.ch/en/showcode.php?id=152 Windows only. Old but still works.
in VBA still one of my favorite Functions, because of the FOF_ALLOWUNDO-Flag for Deleting
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

AlexTP

  • Hero Member
  • *****
  • Posts: 1765
    • UVviewsoft
Re: Copying an entire directory (incl. subdirectories)
« Reply #31 on: January 24, 2022, 12:52:29 pm »
@CM360
Maybe make a pull-request. I don't know the Copydir code, so cannot fix.

Josh

  • Hero Member
  • *****
  • Posts: 930
Re: Copying an entire directory (incl. subdirectories)
« Reply #32 on: January 24, 2022, 05:45:32 pm »
@Alextp

Attached a copy of my modified copydir routine that allows

Code: [Select]
* 2021.06.07 - changes by Josh on Lazarus Forum
* Added _copyAllFiles _copyOnlyIfExists,_copyIfNewer,_copyIfSizeChanged,
*    _abortcopy,_copycomparefiles:Boolean
*
*    Ability to AbortCopy Routine by useer setting _Abortcopy to true in GUI.
*
*    Ability To Keep App Responsive
*    _AppProcessMessagesCounterInterval:integer;
*    _keepalive:boolean;
*
*    Configureable Buffer Copy
*    _usebufferedcopy:boolean;
*    _comparebuffersize:LongInt;
*    _CopyBuffer,_CompBuffer1,_CompBuffer2:Array of Byte;
*    _copybuffersize:LongInt;
*
*    Variables to keep Track of Routine for User
*    _CopyDirProcessedFromFile:String;
*    _CopyDirProcessedFromFileSize:int64;
*    _TotalBytesToCopy,_TotalByteProcessed,_ActutalBytesCopied,_appproctickcounter:Qword;

attached Demo project using this routine allowing you to choose all avaiable options to test.

Thought I would post changes I made in-case the changes are suitable for main repository.

« Last Edit: January 24, 2022, 05:54:08 pm by josh »
Development Installation Lazarus 1.3, FPC 2.7.1,Windows 7/8 32/64, OSX, *nix

Test Environment Lazarus & FPC Trunk on Windows and OSX (Cocoa Mainly on OSX). Testing also Crosscompile windows to OSX.. 
Any posts made from 2015 will be based on Lazarus Trunk.

AlexTP

  • Hero Member
  • *****
  • Posts: 1765
    • UVviewsoft
Re: Copying an entire directory (incl. subdirectories)
« Reply #33 on: January 24, 2022, 06:05:02 pm »
@josh,
No wish to dig in new additions, sorry, so I trusted you and posted your files to repo
https://github.com/Alexey-T/CopyDir-Lazarus

Josh

  • Hero Member
  • *****
  • Posts: 930
Re: Copying an entire directory (incl. subdirectories)
« Reply #34 on: January 24, 2022, 06:28:51 pm »
Cool

Thanks it also give me a place to locate it if I loose my version :)

If I remember it should be pretty much backwards compatible with previous version, obviously the keepAlive routines are gui only and an ifdef lcl is used to add needed units/classes for gui operation.
Development Installation Lazarus 1.3, FPC 2.7.1,Windows 7/8 32/64, OSX, *nix

Test Environment Lazarus & FPC Trunk on Windows and OSX (Cocoa Mainly on OSX). Testing also Crosscompile windows to OSX.. 
Any posts made from 2015 will be based on Lazarus Trunk.

Josh

  • Hero Member
  • *****
  • Posts: 930
Re: Copying an entire directory (incl. subdirectories)
« Reply #35 on: January 24, 2022, 06:54:27 pm »
Hi Alextp

Just checked the repo; i noticed the the src folder has an un modified copydir.pas file,
and the Josh_src folder has the modified version.
could the modified version have the following added to the header..

Thanks
Josh

* Added _copyAllFiles _copyOnlyIfExists,_copyIfNewer,_copyIfSizeChanged,
*    _abortcopy,_copycomparefiles:Boolean
*
*    Ability to AbortCopy Routine by useer setting _Abortcopy to true in GUI.
*
*    Ability To Keep App Responsive
*    _AppProcessMessagesCounterInterval:integer;
*    _keepalive:boolean;
*
*    Configureable Buffer Copy
*    _usebufferedcopy:boolean;
*    _comparebuffersize:LongInt;
*    _CopyBuffer,_CompBuffer1,_CompBuffer2:Array of Byte;
*    _copybuffersize:LongInt;
*
*    Variables to keep Track of Routine for User
*    _CopyDirProcessedFromFile:String;
*    _CopyDirProcessedFromFileSize:int64;
*    _TotalBytesToCopy,_TotalByteProcessed,_ActutalBytesCopied,_appproctickcounter:Qword;
*

Development Installation Lazarus 1.3, FPC 2.7.1,Windows 7/8 32/64, OSX, *nix

Test Environment Lazarus & FPC Trunk on Windows and OSX (Cocoa Mainly on OSX). Testing also Crosscompile windows to OSX.. 
Any posts made from 2015 will be based on Lazarus Trunk.

AlexTP

  • Hero Member
  • *****
  • Posts: 1765
    • UVviewsoft
Re: Copying an entire directory (incl. subdirectories)
« Reply #36 on: January 24, 2022, 07:41:49 pm »
@Josh, I added history.txt from your text.

CM630

  • Hero Member
  • *****
  • Posts: 988
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: Copying an entire directory (incl. subdirectories)
« Reply #37 on: January 25, 2022, 08:03:02 am »


@CM360
Maybe make a pull-request. I don't know the Copydir code, so cannot fix.
The best solution is to use GettTickCount64 instead of GettickCount, but this will break compatibility with WinXP.
So in this particular case, it could be:


Code: Pascal  [Select][+][-]
  1. ...
  2. Function SafeSubtract(Now : Int64; Before : Int64) : Int64;
  3. begin
  4.  Result := (Now - Before) And $FFFFFFFF;
  5. end;
  6. ....
and replace
  self._AddToLog('COPYING DONE (in ' + IntToStr(GetTickCount - __startTime) +   ' ms)');
with
  self._AddToLog('COPYING DONE (in ' + IntToStr(SafeSubtract(GetTickCount - __startTime)) +   ' ms)');
Лазар 2,2,0 32 bit; FPC3,2,2; rev: Lazarus_2_2_0 on W10 64bit.

PascalDragon

  • Hero Member
  • *****
  • Posts: 4005
  • Compiler Developer
Re: Copying an entire directory (incl. subdirectories)
« Reply #38 on: January 25, 2022, 09:06:52 am »
@CM360
Maybe make a pull-request. I don't know the Copydir code, so cannot fix.
The best solution is to use GettTickCount64 instead of GettickCount, but this will break compatibility with WinXP.

As long as you use SysUtils.GetTickCount64 it falls back to GetTickCount if GetTickCount64 is not available.

AlexTP

  • Hero Member
  • *****
  • Posts: 1765
    • UVviewsoft
Re: Copying an entire directory (incl. subdirectories)
« Reply #39 on: January 25, 2022, 02:00:42 pm »
Replaced GetTickCount->GetTickCount64.
BTW, we use LCLIntf.GetTickCount64, not from SysUtils.

EDIT: it's the same as SysUtils one.
« Last Edit: January 25, 2022, 02:02:33 pm by Alextp »

Josh

  • Hero Member
  • *****
  • Posts: 930
Re: Copying an entire directory (incl. subdirectories)
« Reply #40 on: January 25, 2022, 02:54:13 pm »
@Alextp,
I should have mentioned I changed to GetTickCount64 in the moded version; changed the necessary vars from DWord to QWord.
« Last Edit: January 25, 2022, 03:26:06 pm by josh »
Development Installation Lazarus 1.3, FPC 2.7.1,Windows 7/8 32/64, OSX, *nix

Test Environment Lazarus & FPC Trunk on Windows and OSX (Cocoa Mainly on OSX). Testing also Crosscompile windows to OSX.. 
Any posts made from 2015 will be based on Lazarus Trunk.

 

TinyPortal © 2005-2018