Recent

Author Topic: Copying an entire directory  (Read 11760 times)

Logic_Bomb

  • New Member
  • *
  • Posts: 41
Copying an entire directory
« on: October 10, 2011, 07:59:50 pm »
I have recently come across the need to copy an entire directory (including all file & sub directories) to another drive from within Pascal, I have looked everywhere and cannot seem to find any help on this issue and there doesn't seem to be a function for it from within Lazarus.

Any tips or Ideas? The files & sub-folders within the directory in question will not be constant and the directory could be quite big, so has anyone any ideas on how to implement this?

Help would be appreciated.

Thanks

Logic_Bomb.

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Copying an entire directory
« Reply #1 on: October 10, 2011, 08:25:13 pm »
http://www.lazarus.freepascal.org/index.php/topic,14872.0.html

On Windows, you can do:

Code: [Select]
// uses ShellApi, Windows
function CopyDir(const fromDir, toDir: string): Boolean;
var
  fos: TSHFileOpStruct;
begin
  ZeroMemory(@fos, SizeOf(fos));
  with fos do
  begin
    wFunc  := FO_COPY;
    fFlags := FOF_FILESONLY;
    pFrom  := PChar(fromDir + #0);
    pTo    := PChar(toDir)
  end;
  Result := (0 = ShFileOperation(fos));
end;   
« Last Edit: October 10, 2011, 11:41:40 pm by typo »

Bart

  • Hero Member
  • *****
  • Posts: 5290
    • Bart en Mariska's Webstek
Re: Copying an entire directory
« Reply #2 on: October 11, 2011, 10:17:41 am »
All you need is something to enumerate a directory:
http://home.tiscali.nl/~knmg0017/software/fpc_laz/enumdirs.zip (which has http://home.tiscali.nl/~knmg0017/software/fpc_laz/extmasks.zip as a dependancy) and a routine to copy files (platform independant): http://home.tiscali.nl/~knmg0017/software/fpc_laz/myfileutils.zip

Bart

bastla

  • New Member
  • *
  • Posts: 23
Re: Copying an entire directory
« Reply #3 on: August 30, 2014, 08:49:06 pm »
If someone is still looking for an working solution to this, I started a topic about this some time ago ;)

Cheers
bastla

 

TinyPortal © 2005-2018