DelEmpty by StatusQuo

Discuss and announce Total Commander plugins, addons and other useful tools here, both their usage and their development.

Moderators: Hacker, petermad, Stefan2, white

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

DelEmpty by StatusQuo

Post by *StatusQuo »

2Hacker
My first extended version of your DelEmpty.AHK is ready, working OK in my tests.
I must admit, not very much of your code has survived, but it helped me a lot, thanks again.
I labelled it version 2.0, considering yours as 1.x.

Feature overview:
+ Does not alter any directories existing on both sides, only deletes empty dirs.
+ DelAll mode: Optionally all empty dirs can be deleted (like in TC's SyncTool now) with second parameter /ALL.
+ Preview mode: Only telling what it would delete. No final deletion is done whithout additional third parameter.
+ Confirmation mode: first display target path, then delete after positive confirmation.
+ Cancel/Skip options while previewing.
+ Automatic parameter format correction (as far as possible) and different error messages.

Parameter format for TC (silent mode without confirmation; syntax is also displayed when called without parameters):

Code: Select all

"%T\" "%P\" /X
Disclaimer:
Works as expected in my tests, but use at your own risk.
If someone finds any bugs, please let me know.

Download of compiled exe (together with source): Download V2.02 (dropbox)

AHK source:

Code: Select all

; Usage with TC: 
; You have to put the following into the TC Parameters field:
;
; Silent Execute mode: only tells about errors, no unneeded status info
; "%T\" "%P\" /X
;
; Confirmation mode: replace "/X" with "/XC" to ask for confirmation before deleting each dir
; "%T\" "%P\" /XC
;
; Preview mode: leave out the "/X" to only display the name of folders to delete (no deletion is done):
; "%T\" "%P\"
;
; DelAll mode: replace the second path with "/ALL" to delete ALL empty folders in the first directory:
; "%T\" /ALL /XC
;
; IMPORTANT:
; order of parameters must be kept:
; TARGET as #1, COMPARE-SOURCE or /ALL as #2, /X as #3

#NoEnv

Version = 2.02
StringUpper, ScriptName, A_ScriptName
Syntax = /////////////////////////////////////////////////////////////////
Syntax = %Syntax%`n/// %ScriptName% V%Version%    (W) StatusQuo 2007-2008
Syntax = %Syntax%`n
Syntax = %Syntax%`nSyntax:   %ScriptName%  <target-dir_delete-empty>\\  [<source-dir_compare>\\ | /ALL]  [/X | /XC]
Syntax = %Syntax%`n                ==> A trailing backspace has to be doubled or omitted!!
; Syntax = %Syntax%`n                (attaching a dot instead should help, too => "D:\.")	; ! not working in some tests !
Syntax = %Syntax%`n`n=>In TC use:
Syntax = %Syntax%`n`n   "`%T\"  "`%P\"  /X
Syntax = %Syntax%`nto delete single empty dirs in the target (inactive) panel silently.
Syntax = %Syntax%`n`n   "`%T\"  "`%P\"  /XC
Syntax = %Syntax%`ndoes the same, but asks for confirmation for every dir,
Syntax = %Syntax%`n`n   "`%T\"  "`%P\"
Syntax = %Syntax%`nto only report the empty dirs to the user, without really deleting them (preview mode).
Syntax = %Syntax%`n`n   "`%T\"  /ALL  /XC
Syntax = %Syntax%`nto delete ALL empty dirs in the target (inactive) panel after asking for confirmation.
Syntax = %Syntax%`n`n`n=> Special thanks to Hacker for the inspiration and examples.

nFound = 0
nDeleted = 0

StringUpper, test, 3		; test = %3%
boIsSilent    := (test = "/X")
boIsConfirm   := (test = "/XC")
boIsPreview   := (test=)

StringUpper, test, 2		; test = %2%
boDelAllEmpty := (test = "/ALL")

test = %2%
test := StrLen(test)
	; 0 parameters - too few parameters
if (%test% = 0)
{	MsgBox, 16, %A_ScriptName% %Version%, Parameter error: `nMissing parameters. `n`n%Syntax%
	exit 255
}
	; 1 parameter, 2nd parameter empty => cause can be missing DOUBLE backslash at parameter end
If test = 0
{	MsgBox, 16, %A_ScriptName% %Version%, Parameter error: `nToo few parameters  OR  missing  DOUBLE backslash  at parameter ends. `n`n%Syntax%
	exit 254
}
	; dir for comparing not existing
if (boDelAllEmpty)
{
	2 := "NUL"
} else {
	IfNotExist, %2%
	{	MsgBox, 16, %A_ScriptName% %Version%, Parameter error: `nNot found:  Directory structure for comparing. `n`n%Syntax%
		exit 253
	}
}
	; correct format of first 2 parameters
Loop, 2
{
	StringMid, TestPar, %A_Index%, 1
		; skip, if Parameter is an option, no dir name
	test := SubStr(TestPar, 1, 1)
	IfEqual, test, /
	{	continue
	}
		; add missing backslash at string end
	test := SubStr(TestPar, StrLen(TestPar), 1)
	IfNotEqual, test, `\
	{	%A_Index% = %TestPar%\
	}
		; remove duplicate backslashes at string end
	Loop
	{	StringMid, TestPar, %A_Index%, 1
		if StrLen(TestPar)<2		; only 1 char left
			break
		test := SubStr(TestPar, StrLen(TestPar)-1, 1)
		IfNotEqual, test, `\	; done
			break
		%A_Index% := SubStr(TestPar, 1, StrLen(TestPar)-1)
	}
}

Loop, %1%*.*, 2, 1
{
	Empty=1
	Loop, %A_LoopFileLongPath%\*.*, 0, 1	; recursively search for contained directories
	{	Empty=0
		Break
	}
		; after here we get only empty dirs (without files)
	IfEqual, Empty, 0		; if contents are found, go to next directory
	{	Continue
	}
	
	;IfExist, %2%			; %2% existing, already tested above
	{	target_process=%A_LoopFileLongPath%
		StringReplace, source_compare, target_process, %1%, %2%	; build path to compare

		IfExist, %source_compare%		; dir exists in compare-source dir - no delete, go on with next dir
		{	Continue
	}	}
	
	;nFound  = 1
	nFound += 1
	if boIsSilent			; /X given: Silent Execute mode, only delete
	{	FileRemoveDir, %target_process%, 1	; force: also delete, if it contains folders, but no files
		nDeleted += 1
	}
	else if boIsConfirm	; /XC given: Confirmation mode, delete AND echo
	{	;Msgbox, 3,, (Confirmation mode) `n`nDelete         : %target_process%`n-because-`nnot found in: %2%
		Msgbox, 3,, (Confirmation mode) `n`nNot found in: %2%`n-so-`ndelete         : %target_process%
		IfMsgbox, No
			continue
		IfMsgBox, Cancel
			exit
		FileRemoveDir, %target_process%, 1	; force: also delete, if it contains folders, but no files
		nDeleted += 1
	} else					; without /X, /XC: Preview mode, only show, do not delete anything
	{	;Msgbox, 1,, (Preview mode, only show) `n`nDelete         : %target_process%`n-because-`nnot found in: %2%
		Msgbox, 1,, (Preview mode, only show) `n`nNot found in: %2%`n-so-`ndelete         : %target_process%
		IfMsgBox, Cancel
			exit
}	}

sOut = 
if nFound=0
{	sOut = No empty dirs found in `n   %1%
} 
else
{	if nFound > 1
		sOut = %nFound% empty dirs found in `n   %1%
	else
		sOut = %nFound% empty dir found in `n   %1%
	;if nDeleted
		sOut = %sOut% `n%nDeleted% removed.
}
if not boIsSilent		; in Silent Execute mode also don't display summary
	MsgBox %sOut%
Edits:
- Update to V2.01
- Update to V2.02: added support for parameter "/ALL"
Last edited by StatusQuo on 2016-02-22, 21:35 UTC, edited 8 times in total.
Who the hell is General Failure, and why is he reading my disk?
-- TC starter menu: Fast yet descriptive command access!
StatusQuo
Power Member
Power Member
Posts: 1524
Joined: 2007-01-17, 21:36 UTC
Location: Germany

Post by *StatusQuo »

2ghisler(Author)
How about implementing a similar version into TC's SyncTool?

Code: Select all

[ ] Right: Delete all  empty directories
[ ] Right: Delete only empty directories not existing on the left
Programming the main part should be quite easy to do, as you already have the code for finding and deleting:
After finding an empty dir to delete, replace the part with the user-selected dir on the right with the string on the left -
if the directory with this name (in the source dir) exists, then don't delete and proceed with the next dir.

D:\target\dir\subdir\emptydir => don't delete if this exists:
D:\source\dir\subdir\emptydir

From the AHK-code above:

Code: Select all

	{	target_process=%A_LoopFileLongPath%
		StringReplace, source_compare, target_process, %1%, %2%	; build path to compare

		IfExist, %source_compare%		; dir exists in compare-source dir - no delete, go on with next dir
		{	Continue
	}	}
Example "1-liner" in TP:

Code: Select all

Var
   sTarget,
   sSource,
   sTargetDelPath,
   sSourceCmpPath: String;

begin
   sSource        := 'D:\source\dir\subdir';       { selected by user }
   sTarget        := 'D:\target\dir\subdir';       { selected by user }
   sTargetDelPath := 'D:\target\dir\subdir\emptydir'; { found by TC }

   sSourceCmpPath := sSource +
                      Copy( sTargetDelPath,   Length(sTarget)+1,
                     Length(sTargetDelPath) - Length(sTarget)+1 );
end.
What do you think?
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:

Post by *eugensyl »

2StatusQuo

DelEmpty 2.0 (exe) is reported as virus by F-prot.

Can anyone confirm?
My Best Wishes,

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

Post by *StatusQuo »

2eugensyl
I guess the AHK compiler 1.0.46.12 is the problem and the virus scanner is to blame.
While installing AHK I got a warning about a virus in AutoHotkeySC.bin (used by the AHK compiler) from the Avira scanner. I sent it to Avira for analyzing, they classified it a false positive and removed the problem in their next virus definitions update.

I also sent it to Frisk now, too, so maybe with one of the next definition updates also F-Prot no longer complains about it.

If you'd like to try for yourself: The AHK package can be downloaded here: http://www.autohotkey.com/download/AutoHotkey104612.zip
No installation needed, just unpack and call the compiler:

Code: Select all

ahk2exe /in DelEmpty.ahk
I compiled the same code again with AHK version 1.0.46.08 (was no problem here with Avira scanner),
you can get this compiled version from here.
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:

Post by *eugensyl »

StatusQuo wrote:2eugensyl
I compiled the same code again with AHK version 1.0.46.08 (was no problem here with Avira scanner),
you can get this compiled version from here.
Thanks! It's ok now.
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 for checking.
Who the hell is General Failure, and why is he reading my disk?
-- TC starter menu: Fast yet descriptive command access!
StatusQuo
Power Member
Power Member
Posts: 1524
Joined: 2007-01-17, 21:36 UTC
Location: Germany

Post by *StatusQuo »

Small update, containing some cosmetics and status info (telling how many empty dirs were deleted, if any):
the archive including compiled version, source code and example for integration in TC

can be found here (V2.01).

Short help gets displayed when called without parameters or with only "/?"
and is included in the contained source code.
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:

Post by *eugensyl »

2StatusQuo

Good job!
Thank you.

I think 2008 is better into error message (///DELEMPTY V2.01 (W) StatusQuo 2007). Don't you?
It's too new this year...

2Moderator

Maybe it's better to move this topic to Plugins and addons
My Best Wishes,

Eugen
User avatar
Hacker
Moderator
Moderator
Posts: 13142
Joined: 2003-02-06, 14:56 UTC
Location: Bratislava, Slovakia

Post by *Hacker »

[mod]Thread split from Synchronize Dirs... empty dirs.

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 »

2eugensyl
Thanks, glad you like it.
I think 2008 is better into error message
Well, in the next version. ;)
This one is in fact from december, it was just tested some time before release.

2Hacker
Thanks for the smart splitting, this way even updating the first posting got possible again... 8)
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: 13142
Joined: 2003-02-06, 14:56 UTC
Location: Bratislava, Slovakia

Post by *Hacker »

StatusQuo,
;)

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 »

This issue will hopefully be solved (making this DelEmpty obsolete) 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!
StatusQuo
Power Member
Power Member
Posts: 1524
Joined: 2007-01-17, 21:36 UTC
Location: Germany

Post by *StatusQuo »

Updated to V2.02 for a request in a german thread
(added missing support for parameter /ALL to delete all empty dirs without comparing to another directory structure).

Code + download link in the OP above.
Who the hell is General Failure, and why is he reading my disk?
-- TC starter menu: Fast yet descriptive command access!
Total-Chris
Junior Member
Junior Member
Posts: 2
Joined: 2016-02-17, 11:02 UTC
Location: Germany

Re: DelEmpty by StatusQuo / No download link to DelEmpty

Post by *Total-Chris »

Hi, the download link to DelEmpty does no longer exist. Message from the box:
"Dieser freigegebene Datei- oder Ordnerlink wurde entfernt. "
(i.e. "The link was removed") .
I'd really would like to use your DelEmpty.
Perhaps you could send it an alterative ways.
Thank you in advance
Chris
hi5
Power Member
Power Member
Posts: 637
Joined: 2012-11-03, 11:35 UTC
Contact:

Post by *hi5 »

@Total-Chris the script is posted in the very first post as well (all that green text in the code block). You need AutoHotkey which you can download at http://autohotkey.com/
F4MiniMenu (Forum) - Open selected file(s) from TC in defined editor(s) - A (minimalistic) clone of F4Menu
Source at GitHub (AutoHotkey). TCSyncComments (copy file comments)
Post Reply