Page 1 of 1

Synchronize Dirs... empty dirs

Posted: 2007-08-07, 09:45 UTC
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

Posted: 2007-08-09, 16:37 UTC
by ghisler(Author)
No, this isn't currently possible, sorry.

Re: Synchronize Dirs... empty dirs

Posted: 2007-08-11, 17:09 UTC
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,

Re: Synchronize Dirs... empty dirs

Posted: 2007-08-13, 01:24 UTC
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...

Re: Synchronize Dirs... empty dirs

Posted: 2007-08-13, 16:16 UTC
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,

Posted: 2007-08-14, 00:21 UTC
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?

Posted: 2007-08-14, 06:33 UTC
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

Posted: 2007-08-14, 16:38 UTC
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.

Posted: 2007-08-15, 15:35 UTC
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

Posted: 2007-08-26, 20:34 UTC
by StatusQuo
2Hacker
Thanks a lot.
I'll try both the AHK solution and expanding the Delphi program, but this will take some time...

Posted: 2007-09-12, 03:25 UTC
by d
folders should be managed as files

Posted: 2008-01-05, 01:58 UTC
by Hacker
[mod]Thread split to DelEmpty by StatusQuo.

Hacker (Moderator)[/mod]

Posted: 2008-04-17, 15:56 UTC
by StatusQuo
This issue will hopefully be solved in TC 7.5:
http://ghisler.ch/board/viewtopic.php?p=144998#144998