Delete empty folders recursively routine?

John Baughman (5/9/14 8:09AM)
Jeremy Roussak (5/9/14 11:24AM)


John Baughman (5/9/14 8:09 AM)

Decided to add my posted method to delete empty folders to my own tool
box. After a bit more testing, here is a revised version that should
work on both mac and windows...

$folderPath:=$1
FOLDER LIST($folderPath;$aFolders)

For ($i;1;Size of array($aFolders))
?=A0?DeleteEmptyFolders_Jut ($folderPath+$aFolders{$i}+Folder
separator)
?//using the folder separator constant for win & mac computability
?=A0?DOCUMENT LIST($folderPath+$aFolders{$i}+Folder
separator;$aDocuments;Ignore invisible) ?//added the ignore invisible
parameter to handle the DS_Store file on Mac
?=A0?if (Size of array($aDocuments)=0)
?=A0?=A0?=A0?=A0DELETE FOLDER($folderPath+$aFolders{$i})

?=A0?End if

End for

John Baughman
Kailua, Hawaii
(808) 262-0328
johnbdh@...

Jeremy Roussak (5/9/14 11:24 AM)

Wayne,

Your code seems to do "rm -r". I think that what David wanted was to
delete no files but only empty folders, which is why I withdrew my
first suggestion. Something along these lines:

pruneEmpties(rootFolder)

for each folder in rootFolder

pruneEmpties(folder)

if folder is empty, delete it

end for

Jeremy

Jeremy Roussak
jbr@...

On 9 May 2014, at 10:54, Wayne Stewart <wayne.b.stewart@...
wrote:

color><param>00000,0000,DDEE/param>DDavid,

Your wish is my command! ?I'm supposed to be studying so this was
perfect study avoidance technique!

Have fun, not fantastically checked & no error testing but what do you
expect?

BTW: Dog is welcome indoors, but only on hard floors, preferably
laundry.

DeleteFolderHierarchy(Get 4D folder(Current Resources
folder)+"Example"+Folder separator)

////////////////////////////////////////////////////////
// ?DeleteFolderHierarchy

C_TEXT($1)

C_LONGINT($CurrentDocument_i;$CurrentFolder_i;$NumberOfDocuments_i;$Number
OfFolders_i)
C_TEXT($PathName_t)

ARRAY TEXT($DocumentPaths_at;0)
ARRAY TEXT($FolderPaths_at;0)

If (False)
C_TEXT(DeleteFolderHierarchy ;$1)
End if

$PathName_t:=$1

DOCUMENT LIST($PathName_t;$DocumentPaths_at;Recursive parsing+Absolute
path)

$NumberOfDocuments_i:=Size of array($DocumentPaths_at)
For ($CurrentDocument_i;1;$NumberOfDocuments_i)
DELETE DOCUMENT($DocumentPaths_at{$CurrentDocument_i})
End for

FOLDER LIST($PathName_t;$FolderPaths_at)

$NumberOfFolders_i:=Size of array($FolderPaths_at)
For ($CurrentFolder_i;1;$NumberOfFolders_i)
DeleteThisFolder ($PathName_t+$FolderPaths_at{$CurrentFolder_i})
End for

DeleteThisFolder ($PathName_t)

////////////////////////////////////////////////////////
// DeleteThisFolder

C_TEXT($1)

C_LONGINT($CurrentFolder_i;$NumberOfFolders_i)
C_TEXT($PathName_t)

ARRAY TEXT($FolderPaths_at;0)

If (False)
C_TEXT(DeleteThisFolder ;$1)
End if
$PathName_t:=$1

FOLDER LIST($PathName_t;$FolderPaths_at)

$NumberOfFolders_i:=Size of array($FolderPaths_at)

For ($CurrentFolder_i;1;$NumberOfFolders_i)
DeleteThisFolder ($PathName_t+Folder
separator+$FolderPaths_at{$CurrentFolder_i})
End for

DELETE FOLDER($PathName_t)

////////////////////////////////////////////////////////
// ?Compiler_DeleteFolders

If (False)
C_TEXT(DeleteFolderHierarchy ;$1)
C_TEXT(DeleteThisFolder ;$1)
End if
Regards,

Wayne

On 9 May 2014 18:36, Jeremy Roussak <jbr@... wrote:
/color><color><param>8826F,0000,8219/param>II should read and think
more carefully before replying. That's an obviously wrong answer which
should be ignored. Apologies.

Jeremy Roussak
jbr@...

On 9 May 2014, at 09:31, Jeremy Roussak <jbr@... wrote:

/color><color><param>FFC79,0365,0771/param>DDavid,

If you're on OS X only, why not just use Unix's rm command with the -r
option?

Jeremy

Jeremy Roussak
jbr@...

On 9 May 2014, at 09:02, David Adams <dpadams@... wrote:

I just looked in my bag of tricks and find that I don't already have a
routine to clear out empty folders. The idea being:

* Pass in a starting path.
* Walk down into the folder structure and clear out any empty folders.

13.5, OS X only.

I can write this but it sounds like the sort of thing others have
already
written and debugged. Does anyone have a simple utility of that sort
that
they would be up for sharing?

Thanks in advance, no matter what.
/color>

Reply to this message

Summary created 5/11/14 at 1:31AM by Intellex Corporation

Comments welcome at: feedback@intellexcorp.com