Synchronize Dirs... empty dirs

Here you can propose new features, make suggestions etc.

Moderators: white, Hacker, petermad, Stefan2

Post Reply
tempUser
New Member
New Member
Posts: 1
Joined: 2007-08-07, 09:36 UTC

Synchronize Dirs... empty dirs

Post by *tempUser »

Hi
I wonder why TC asks to "delete all empty directories" when synchronizing

I may have several important empty dirs which I do want to transfer to dest path, but I also want some empty dirs which have no counterpart in the source path to be deleted from the dest path.

Isn't it possible to delete just those empty directories which do not exist in the source path ? I mean it should make the source and dest dirs structurally equal regardless of anything else (whether the folders are empty or not)

Thank you in advance
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48097
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

No, this isn't currently possible, sorry.
Author of Total Commander
https://www.ghisler.com
User avatar
eugensyl
Power Member
Power Member
Posts: 564
Joined: 2004-06-03, 18:27 UTC
Location: România
Contact:

Re: Synchronize Dirs... empty dirs

Post by *eugensyl »

tempUser wrote:Hi
I wonder why TC asks to "delete all empty directories" when synchronizing

I may have several important empty dirs which I do want to transfer to dest path, but I also want some empty dirs which have no counterpart in the source path to be deleted from the dest path.

Isn't it possible to delete just those empty directories which do not exist in the source path ? I mean it should make the source and dest dirs structurally equal regardless of anything else (whether the folders are empty or not)

Thank you in advance

You can use DelEmpty.exe utility for this job.
Make a button and add %P parameter.


Best wishes,
My Best Wishes,

Eugen
StatusQuo
Power Member
Power Member
Posts: 1524
Joined: 2007-01-17, 21:36 UTC
Location: Germany

Re: Synchronize Dirs... empty dirs

Post by *StatusQuo »

eugensyl wrote:
tempUser wrote:Hi
Isn't it possible to delete just those empty directories which do not exist in the source path ?
[...]
You can use DelEmpty.exe utility for this job.
Make a button and add %P parameter.
Just to be sure: The goal would be to not delete all empty dirs, but only those not existing on the other TC panel/side.
E.g. a directory "incoming" of some program would often be empty, but should never be deleted.

Thanks for your hint, but unfortunately I found no link to DelEmpty.exe in the above posting.
Do you mean Hacker's implementation (I think this one doesn't provide the desired function)?

I'm testing some things on this topic, too, but they are still far from being ready...
Who the hell is General Failure, and why is he reading my disk?
-- TC starter menu: Fast yet descriptive command access!
User avatar
eugensyl
Power Member
Power Member
Posts: 564
Joined: 2004-06-03, 18:27 UTC
Location: România
Contact:

Re: Synchronize Dirs... empty dirs

Post by *eugensyl »

Do you mean Hacker's implementation (I think this one doesn't provide the desired function)?
I think yes.
This is the file.

For me it's work.


Best wishes,
My Best Wishes,

Eugen
StatusQuo
Power Member
Power Member
Posts: 1524
Joined: 2007-01-17, 21:36 UTC
Location: Germany

Post by *StatusQuo »

2eugensyl
Thanks, but I miss the second directory-parameter. I assume that it "simply" deletes all empty dirs - without exist-checks on another dir structure.

2Hacker
Maybe you can find some time for an extended version? 8)
Do you still offer the source code for free?
Who the hell is General Failure, and why is he reading my disk?
-- TC starter menu: Fast yet descriptive command access!
User avatar
Hacker
Moderator
Moderator
Posts: 13073
Joined: 2003-02-06, 14:56 UTC
Location: Bratislava, Slovakia

Post by *Hacker »

Maybe you can find some time for an extended version?
Sure can try.
Do you still offer the source code for free?
Here you are, DelEmpty.dpr:

Code: Select all

program DelEmpty;

{$APPTYPE CONSOLE}

uses
  SysUtils, StrUtils, Windows;

var
  basepath: string;
  del: boolean;
  fp: boolean;
  i: integer;

procedure givehelp;
  begin
    writeln;
    writeln('DelEmpty 1.03, 25 Mar 2004');
    writeln('By Roman Korcek <thehacker@host.sk>, <roman_korcek@hotmail.com>');
    writeln;
    writeln('Shows and eventually deletes empty dirs recursively from a given path.');
    writeln;
    writeln('Usage:');
    writeln('delempty <path> [del] [fp]');
    writeln;
    writeln('path: the start path - only subdirs of this dir will be checked');
    writeln(' del: shows and DELETES empty dirs found under <path>');
    writeln('  fp: shows the full (not just relative to <path>) path when listing empty dirs');
    writeln;
    writeln('Note:');
    writeln('When deleting, a dir is also considered empty if it contains other empty dirs.');
    writeln('When NOT deleting, only truly empty dirs will be shown.');
    halt;
  end;

function nulltermstr(strn: string): PChar;
begin
  result := pchar(strn);
end;


procedure processdir(thisdir: string);
var
  fileinfo: tsearchrec;
  errormessage: array [0..80] of char;

begin
  chdir(thisdir);

  // if we're in the root dir...
  if length(getcurrentdir) = 3 then
    begin
      if findfirst('*.*', faAnyFile, fileinfo) = 0 then
        if fileinfo.attr and faDirectory <> 0 then
          processdir(includetrailingpathdelimiter(expandfilename(fileinfo.name)));
    end
  else  // we're not in the root dir, we need to skip '.' and '..'
    begin
      findfirst('*.*', faAnyFile, fileinfo);
      findnext(fileinfo);
    end;

  while findnext(fileinfo) = 0 do
    if fileinfo.attr and faDirectory <> 0 then
      processdir(includetrailingpathdelimiter(expandfilename(fileinfo.name)));
  sysutils.findclose(fileinfo);

  if thisdir <> basepath then
    begin
      findfirst('*.*', faAnyFile, fileinfo);
      findnext(fileinfo);
      if findnext(fileinfo) <> 0 then
        begin
          sysutils.findclose(fileinfo);
          if fp = true then
            writeln(ifthen(del, 'Deleting: '), thisdir)
          else
            writeln(ifthen(del, 'Deleting: '), rightstr(leftstr(basepath,length(basepath)-1),
             length(basepath)-lastdelimiter('\', basepath)+1), '\',
             extractrelativepath(basepath, thisdir));
          chdir('..');
          if del = true then
            if removedirectory(nulltermstr(thisdir)) = FALSE then
              begin
                formatmessage(FORMAT_MESSAGE_FROM_SYSTEM, NIL, getlasterror, 0, errormessage, 80, NIL);
                writeln('Failed. Reason: ' + errormessage);
              end;
        end
      else
        begin
          sysutils.findclose(fileinfo);
          chdir('..');
        end;
    end;
end;

begin
  if (paramcount < 1) or (paramcount > 3) then
    givehelp;

  for i := 2 to paramcount do
    begin
      if ansiuppercase(paramstr(i)) = 'DEL' then
        del := true
      else
        if ansiuppercase(paramstr(i)) = 'FP' then
          fp := true;
    end;

  basepath := includetrailingpathdelimiter(expandfilename(paramstr(1)));
  if directoryexists(basepath) = false then
    begin
      writeln('Incorrect path given.');
      givehelp;
    end
  else
    begin
      if length(basepath) = 3 then
        fp := true;
      processdir(basepath);
    end;
end.
HTH
Roman
Mal angenommen, du drückst Strg+F, wählst die FTP-Verbindung (mit gespeichertem Passwort), klickst aber nicht auf Verbinden, sondern fällst tot um.
StatusQuo
Power Member
Power Member
Posts: 1524
Joined: 2007-01-17, 21:36 UTC
Location: Germany

Post by *StatusQuo »

Hacker wrote:Here you are, DelEmpty.dpr:
Great! I'll try my luck with it (I hope, FreePascal will be enough to compile, let's see), thanks a lot for now.
Who the hell is General Failure, and why is he reading my disk?
-- TC starter menu: Fast yet descriptive command access!
User avatar
Hacker
Moderator
Moderator
Posts: 13073
Joined: 2003-02-06, 14:56 UTC
Location: Bratislava, Slovakia

Post by *Hacker »

And here is also a short AHK script, to "clone" empty directories. First, it deletes all empty dirs on the target side, then copies all empty dirs from the source side and finally sets all the target dirs' attributes and timestamps to those of the source dirs.

Usage:
You have to put the following into the Parameters field:

Code: Select all

"%P\" "%T\"
The script:

Code: Select all

#NoEnv

; Keep looping over target dir structure until no empty dir can be found / deleted
EmptyDirDeleted = 0
Loop,
{
	Loop, %2%*.*, 2, 1
	{
		FileRemoveDir, %A_LoopFileLongPath%, 0
		IfEqual, ErrorLevel, 0
			EmptyDirDeleted = 1
	}

	IfEqual, EmptyDirDeleted, 0
		Break

	EmptyDirDeleted = 0
}

; Copy all empty dirs from source dir structure
Empty = 1
Loop, %1%*.*, 2, 1
{
	Loop, %A_LoopFileLongPath%\*.*, 1
		Empty = 0

	IfEqual, Empty, 1
	{
		; Keep the dir structure
		StringReplace, TargetDir, A_LoopFileLongPath, %1%, %2%

		FileCopyDir, %A_LoopFileLongPath%, %TargetDir%
		Empty = 0
	}

	Empty = 1
}

; Copy all dirs' attributes
Loop, %2%*.*, 2, 1
{
	StringReplace, SourceDir, A_LoopFileLongPath, %2%, %1%
	IfExist, %SourceDir%
	{
		FileGetAttrib, Attribs, %SourceDir%
		StringReplace, Attribs, Attribs, D
		StringReplace, Attribs, Attribs, C
		FileSetAttrib, +%Attribs%, %A_LoopFileLongPath%, 2
		FileGetTime, Time, %SourceDir%
		FileSetTime, %Time%, %A_LoopFileLongPath%, , 2
		FileGetTime, Time, %SourceDir%, C
		FileSetTime, %Time%, %A_LoopFileLongPath%, C, 2
		FileGetTime, Time, %SourceDir%, A
		FileSetTime, %Time%, %A_LoopFileLongPath%, A, 2
	}
}
HTH
Roman
Mal angenommen, du drückst Strg+F, wählst die FTP-Verbindung (mit gespeichertem Passwort), klickst aber nicht auf Verbinden, sondern fällst tot um.
StatusQuo
Power Member
Power Member
Posts: 1524
Joined: 2007-01-17, 21:36 UTC
Location: Germany

Post by *StatusQuo »

2Hacker
Thanks a lot.
I'll try both the AHK solution and expanding the Delphi program, but this will take some time...
Who the hell is General Failure, and why is he reading my disk?
-- TC starter menu: Fast yet descriptive command access!
d
Member
Member
Posts: 157
Joined: 2007-02-05, 14:54 UTC

Post by *d »

folders should be managed as files
User avatar
Hacker
Moderator
Moderator
Posts: 13073
Joined: 2003-02-06, 14:56 UTC
Location: Bratislava, Slovakia

Post by *Hacker »

[mod]Thread split to DelEmpty by StatusQuo.

Hacker (Moderator)[/mod]
Mal angenommen, du drückst Strg+F, wählst die FTP-Verbindung (mit gespeichertem Passwort), klickst aber nicht auf Verbinden, sondern fällst tot um.
StatusQuo
Power Member
Power Member
Posts: 1524
Joined: 2007-01-17, 21:36 UTC
Location: Germany

Post by *StatusQuo »

This issue will hopefully be solved in TC 7.5:
http://ghisler.ch/board/viewtopic.php?p=144998#144998
Who the hell is General Failure, and why is he reading my disk?
-- TC starter menu: Fast yet descriptive command access!
Post Reply