autodelete folder content every night

Showing results for 
Search instead for 
Did you mean: 
Active Member

autodelete folder content every night

Hi, i'm on Community version 6.2 and i'm new to Alfresco at all. I just need for the simplest way for delete the content of a specific folder every night.

These folder is just a temporary passtrough, often users left files here which are useless...

Thanks in advance for any help!

2 Replies
Alfresco Employee

Re: autodelete folder content every night

Hi @TheCondor,

Welcome to Alfresco!

You might find this thread useful. This blog post is also worth reading. There is also this thread, that suggests a scheduled action.

You could also use the API to delete the folder & all its children - you could have a script that is run as a scheduled job & it would have to be run under admin user I believe. The "permanent=false" flag puts the content into the trashcan.

 To delete only the children, you could use this API call:


Digital Community Manager, Alfresco Software.
Problem solved? Click Accept as Solution!

Re: autodelete folder content every night

When you say "way for delete the content of a specific folder every night",

You can write a scheduled job that will run on schedule and deletes the files in the configured folder. 

Refer these docs to learn more on scheduled jobs:

Your scheduled job could be something like:

public class FolderCleanupJobProcessor extends AbstractScheduledLockedJob {

	private NodeService nodeService;

	private SearchService searchService;

	private TransactionService transactionService;
	private String deleteNodesSearchQuery;
	public void executeJob(final JobExecutionContext jobCtx)
			throws JobExecutionException {
		try {
			// Run as system user since this job is user independent hence
			// permission is required on repository
			//Create a method to get the file nodes from the configured folder
			//getListOfFilesFromArchiveFolder method can execute a search query and fetch all the nodes from the configured folder for deletion.
			final List<NodeRef> toBeDeletedNodes = getListOfFilesFromArchiveFolder();
			if (null != toBeDeletedNodes && !toBeDeletedNodes.isEmpty()) {
				for (final NodeRef nodeRef : toBeDeletedNodes) {
					final RetryingTransactionCallback<Object> txnWork = new RetryingTransactionCallback<Object>() {
						public Object execute() throws Exception {
							// Delete the nodeRef
							if (nodeService.exists(nodeRef)) {
							return null;
		} catch (Exception excp) {
			//LOG Errors 
	//This method can execute a search query and fetch all the nodes from the configured folder for deletion.
	private List<NodeRef> getListOfFilesFromArchiveFolder() {
		List<NodeRef> nodeRefList = null;
		ResultSet results = null;
		try {
			//deleteNodesSearchQuery is for example: PATH:"/app:company_home/app:dictionary/cm:yourFolderName//*"
			//considering your folder is in /Company Home/Data Dictionary/ folder. You can adjust the search query depending on the location of your archive folder.
			//if your folder is in a site then, query could be something like: PATH:"/app:company_home/st:sites/cm:test-site/cm:documentLibrary/cm:yourFolderName//*"
			//in the above query, cm:test-site is the site short name.
			results = searchService.query(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, SearchService.LANGUAGE_LUCENE, deleteNodesSearchQuery);
			if (null != results) {
				nodeRefList = results.getNodeRefs();
		} finally {
			if (results != null) {
		return nodeRefList;

	public void setNodeService(final NodeService nodeService) {
		this.nodeService = nodeService;

	public void setSearchService(final SearchService searchService) {
		this.searchService = searchService;
	public void setTransactionService(final TransactionService transactionService) {
		this.transactionService = transactionService;
	public void setDeleteNodesSearchQuery(final String deleteNodesSearchQuery) {
		this.deleteNodesSearchQuery = deleteNodesSearchQuery;

 [EDIT]: @EddieMay already provided useful stuff. Above response is additonal.

(ACSCE, AWS SAA, Azure Admin)