You are viewing limited content. For full access, please sign in.

Question

Question

Delete empty folders

asked on September 2, 2014

 

What would be the most fastest method to delete all empty folders in a repository. This would be a one off  (hopefully) clean up exercise. I have tried using search activity in the WF to find empty folders but this is too slow. There is also the added complication of nested empty folders so there would have to be iterative element to the process.   The repository has about 400k folders.

0 0

Answer

SELECTED ANSWER
replied on September 3, 2014

Yes this will be slow but it will give you exactly what you are after.

It's slow because it goes through all the folders in the repository. Otherwise, you would need to look into a sql query or I will see if I can build one for you.

1 0

Replies

replied on September 2, 2014 Show version history

Below advance search will return all the empty folders in the repository.

 

{LF:Name="*", Type="F"}-{LF:ChildName="*", Type=DFS}

 

Search for all empty folder in the repository using above advance search, select all folders and delete.

6 0
replied on September 3, 2014

Thanks Uzair , I tried this but it has been too slow for the number of folders in the repository especially when considering the nested "empty" folders.

0 0
replied on November 17, 2014

I had the same issue where I just needed to delete folders & subfolders after a document has been deleted.  Louis-Simon Binette (see below) had a good suggestion to created a list of folders from the starting entry, sort them by longest first, then check if emtpy.

Here is the workflow details.  You can run it manually or can use "Invoke Workflow" to call it with a parameter:

<Assign Token Value> Titled, "Create a Folderlist Token"
 Create the following tokens:
 • %(mFolderList) (multi-value)  (token value is blank)
 • %(mEntryPath) = %(Entry Path)

<Conditional Decision> Titled, "Is the starting entry a folder?"
  Yes - a folder:
  If all of these conditions are true
    Starting Entry : Type equals Folder

    If entry is a folder - add the entryname to the path:
    Modify the following tokens:
    • %(mEntryPath) = %(Entry Path)\%(Entry Name)

  No - not a folder:
  continue

<Search Repository> Titled, "Search for folders starting at entry path"
 Search Query:
  {LF:LOOKIN="%(mEntryPath)"} & {LF:Name="*", Type="F"}
 Return: All results

<For Each Entry>  Titled, "For Each Entry" 
    --- loops through the search results to get a list of folders then we'll see if empty -
 
 Iterate through the entries in:
 (Search for folders starting at entry path::Output Entries)

  Assign a Token - append to a token for each folder found
   Modify the following tokens:
   • %(mFolderList): Append %(ForEachEntry_CurrentEntry_FullPath) (multi-value)

--- after the For Each Entry loop ---   
<Assign Token Value> Titled, "Create a Token for Sorting"
 Create the following tokens:
 --- notice the use of the function to sort decending ---
 • %(mSorted) = %(mFolderList#@SortDescending@#) (multi-value)
   
--- let's loop through starting with the longest path name to the shortest --- 
<Repeat> Titled, "Repeat through for each path found"
 If all of these conditions are true
  %(Repeatthroughforeachpathfound_Iteration) is less than or
    equal to %(Searchforfoldersstartingatentrypath_Result Count)
 • Evaluate condition before running contained activities
 • Start the Iteration token at 1
 • Uncheck the "limit the number of repetitions...."

<Find Entry> Titled, "Find Entry"
  Finds the entry at:
  %(mSorted#[%(Repeatthroughforeachpathfound_Iteration)]#)

  --- to prevent a warning in WF results, add a Conditional Decision to check that the folder is empty ---
  <Conditional Decision> Titled, "Is the folder empty?"
  
    Yes - empty folder:
    If all of these conditions are true
      (Find Entry::Output Entry) : Document Count equals 0
      (Find Entry::Output Entry) : Folder Count equals 0

      <Delete Entry> Titled, "Delete Entry"
      Entry to delete: (Find Entry::Output Entry)
      Only delete empty folders

--- note: you could use the "Move Entry" instead of the "Delete Entry" for tracking --
    
    
    No - don't delete:
    do nothing
    
--- end of workflow ---

The shorter the depth of the path, the quicker it runs. 
So to run with only a few folders deep and not many sub-folders, it will take seconds. 

Hope this helps!

Chuck

Workflow - Delete empty folders.jpg
1 0
replied on September 4, 2014 Show version history

Create and execute the following workflow:

 

> search and append ALL folder full paths in a token

> sort the token so subfolders come prior their parent folder

> for each token value, use «Delete Entry» activity with 'Only delete empty folders' option checked

 

Provided access rights are ok, this workflow should do the job...

1 0
replied on September 2, 2014

The fastest way would likely be some type of direct SQL Query that would return all empty folders. I am not aware of that type of query myself though. You would need to have a LF employee help you out with that. I would think though that if you use WF to run a search for all folders, then delete the empty ones, and repeat a few times (maybe 11 depending on how deep you think the folder tree gets) then you would accomplish the same goal without the overhead of complicated searches. 

 

Did you not find an LF Answers article about searching for empty folders directly?

0 0
replied on September 3, 2014

Thanks Kenneth, I think I will have to go down the SQL route to get the job done in a reasonable time. I have not found a LF Article yet on this yet.

0 0
replied on September 8, 2014

Hi Peter, 

 

If your question has been answered, please let us know by clicking the "This answered my question" button on the appropriate response.

 

If you still need assistance with this matter, just update this thread. Thanks!

0 0
replied on May 15, 2017 Show version history

I have come up with this simple workflow, but I don't want it to Search the entire repository as this takes too long.  

I would like to have ability each time I run workflow or business process to run only on a Specific folder in my repository. 

 

 

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.