Create Empty Web Content folder by batch

Is there any way to create Empty web content folder by batch , I need an example for that .

the idea is create “Empty” web content folder by batch .

Using Liferay Latest version : 2025 Q3.8

I must say I don't understand the nature of the request? I mean, how does an empty web content folder help you in any way?

Yes, it helps me build the structure of content folders, reducing manual effort to create folders in each environment and linking them to a specific structure with a defined workflow.

Can't you use site initializer with one sample web content inside the folder?

1 Answer

1

Hello @AhmadQasem,

Currently, there is no out-of-the-box functionality available to create web content folders in batch. However, you can achieve this by using a Groovy script to create the assets in bulk.

Below is an example script for your reference:

import com.liferay.journal.service.JournalFolderLocalServiceUtil
import com.liferay.portal.kernel.service.ServiceContext
import com.liferay.portal.kernel.service.GroupLocalServiceUtil
import com.liferay.portal.kernel.service.CompanyLocalServiceUtil
import com.liferay.portal.kernel.model.Group


long groupId = 20117L        // site groupId
long parentFolderId = 0L     // 0 = root
int totalFolders = 20        // folder1 ... folder20


Group group = GroupLocalServiceUtil.getGroup(groupId)
long companyId = group.getCompanyId()
long userId = CompanyLocalServiceUtil.getCompany(companyId).getDefaultUser().getUserId()


for (int i = 1; i <= totalFolders; i++) {

    String folderName = "folder${i}"

    // check if exists
    def existing = JournalFolderLocalServiceUtil.fetchFolder(
        groupId, parentFolderId, folderName
    )

    if (existing) {
        println "Already exists → ${folderName}"
        continue
    }

    ServiceContext sc = new ServiceContext()
    sc.setScopeGroupId(groupId)

    String erc = "auto_folder_${i}"

    JournalFolderLocalServiceUtil.addFolder(
        erc,              
        userId,
        groupId,
        parentFolderId,
        folderName,
        "Auto-created",
        sc
    )

    println "Created → ${folderName} (ERC: ${erc})"
}

println "--Completed--"

Refer this for other methods as well: liferay-portal/modules/apps/journal/journal-api/src/main/java/com/liferay/journal/service/JournalFolderLocalServiceUtil.java at master · liferay/liferay-portal · GitHub