Removing folders from a directory

0

I have a project in Delphi 2010 in which I use to compress and create backups of WinRAR, through the following code I can compress the following folder teste3 :

AFile := 'C:\teste1\teste2\teste3';
LocateFile := 'C:\Users\Desktop\BACKUPS\'+ FormatDateTime('yyyy-mm-dd', Now) +'.rar';
winexec(PAnsiChar(AnsiString('"C:\Program Files\WinRAR\WinRAR.exe" a '+ LocateFile +' "'+ AFile + '"')), SW_HIDE);

But the compressed file is not showing up as I intended with the folder teste3 , so I leave here the example of what I want.

This is the directory of the teste3 folder:

  

C: \ test1 \ test2 \ test3

Structure:

c:
  teste1
    teste2
      teste3
        exemplo1.txt
        exemplo2.txt
        exemplo3.txt
      ficheiro1.txt
    ficheiro1.txt

When compressed within .rar I have:

ficheiro.rar
  teste1
    teste2
      teste3
        exemplo1.txt
        exemplo2.txt
        exemplo3.txt

What I want:

ficheiro.rar
  teste3
    exemplo1.txt
    exemplo2.txt
    exemplo3.txt

If anyone can contribute anything thank you.

    
asked by anonymous 21.10.2016 / 11:22

1 answer

1

You can use -ep1 , so the home folder will not be added.

In your code use this:

procedure TForm1.Button1Click(Sender: TObject);
var
  AFile: string;
  LocateFile: string;
begin
  AFile := 'C:\teste1\teste2\teste3';
  LocateFile := 'C:\Users\Desktop\BACKUPS\'+ FormatDateTime('yyyy-mm-dd', Now) +'.rar';

  winexec(PAnsiChar(AnsiString('"C:\Program Files\WinRAR\WinRAR.exe" -ep1 a '+ LocateFile +' "'+ AFile + '"')), SW_HIDE);
end;

To ignore empty folders, use -ed .

    
21.10.2016 / 13:14