Synchronize Dirs... empty dirs
Moderators: Hacker, petermad, Stefan2, white
Synchronize Dirs... empty dirs
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
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
- ghisler(Author)
- Site Admin
- Posts: 50479
- Joined: 2003-02-04, 09:46 UTC
- Location: Switzerland
- Contact:
Re: Synchronize Dirs... empty dirs
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
Eugen
Re: Synchronize Dirs... empty dirs
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.eugensyl wrote:You can use DelEmpty.exe utility for this job.tempUser wrote:Hi
Isn't it possible to delete just those empty directories which do not exist in the source path ?
[...]
Make a button and add %P parameter.
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!
-- TC starter menu: Fast yet descriptive command access!
Re: Synchronize Dirs... empty dirs
I think yes.Do you mean Hacker's implementation (I think this one doesn't provide the desired function)?
This is the file.
For me it's work.
Best wishes,
My Best Wishes,
Eugen
Eugen
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?
Do you still offer the source code for free?
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?

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!
-- TC starter menu: Fast yet descriptive command access!
Sure can try.Maybe you can find some time for an extended version?
Here you are, DelEmpty.dpr:Do you still offer the source code for free?
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.
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.
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:
The script:
HTH
Roman
Usage:
You have to put the following into the Parameters field:
Code: Select all
"%P\" "%T\"
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
}
}
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.
This issue will hopefully be solved in TC 7.5:
http://ghisler.ch/board/viewtopic.php?p=144998#144998
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!
-- TC starter menu: Fast yet descriptive command access!