# Auto copy files on folder creation

**URL:** <https://help.nextcloud.com/t/auto-copy-files-on-folder-creation/242382>\
**Category:** 📦 Appliances (Docker, Snappy, VM, NCP, AIO)\
**Tags:** nextcloud, linuxserverio, feature\
**Created:** [March 25, 2026, 5:49pm UTC](https://help.nextcloud.com/t/auto-copy-files-on-folder-creation/242382 "2026-03-25T17:49:32Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![dolphinscorp](https://help.nextcloud.com/letter_avatar/dolphinscorp/32/6_22734026db12803ebb3e059622ac3534.png) [@dolphinscorp](https://help.nextcloud.com/u/dolphinscorp)\
**Post date:** [March 25, 2026, 5:49pm UTC](https://help.nextcloud.com/t/auto-copy-files-on-folder-creation/242382/1 "2026-03-25T17:49:32Z")

</div>

> ****
>

Nextcloud v33

OS Ubuntu 24

I have teamfolder with name US\_Team, now when any user creates a subfolder inside it for example subfolder1, then files should copies from Documents/\* to that Subfolder (i.e. US\_Team/subfolder1/). I have achieved this by system script but problem is that occ scan command takes some times to complete.

Is there any app or or something so that I can achieve this goal via GUI? So we can skip that occ scan command?

---

<div class="post-metadata">

**Author:** ![dolphinscorp](https://help.nextcloud.com/letter_avatar/dolphinscorp/32/6_22734026db12803ebb3e059622ac3534.png) [@dolphinscorp](https://help.nextcloud.com/u/dolphinscorp)\
**Post date:** [March 26, 2026, 7:38am UTC](https://help.nextcloud.com/t/auto-copy-files-on-folder-creation/242382/2 "2026-03-26T07:38:30Z")

</div>

@bb77 do you have any idea?

---

<div class="post-metadata">

**Author:** ![bb77](https://help.nextcloud.com/letter_avatar/bb77/32/6_22734026db12803ebb3e059622ac3534.png) [@bb77](https://help.nextcloud.com/u/bb77)\
**Post date:** [March 26, 2026, 9:20am UTC](https://help.nextcloud.com/t/auto-copy-files-on-folder-creation/242382/3 "2026-03-26T09:20:47Z")

</div>

Not sure, to be honest. Maybe you could put something together with [Flow](https://apps.nextcloud.com/apps/flow), but I don’t have any experience with it.

With your current workflow, you could also try restricting the `occ files:scan` command to a specific path, which should make the scan faster: [Using the occ command — Nextcloud latest Administration Manual latest documentation](https://docs.nextcloud.com/server/28/admin_manual/configuration_server/occ_command.html#file-operations)

---

<div class="post-metadata">

**Author:** ![scubamuc](https://help.nextcloud.com/user_avatar/help.nextcloud.com/scubamuc/32/63165_2.png) [@scubamuc](https://help.nextcloud.com/u/scubamuc)\
**Post date:** [March 26, 2026, 9:28am UTC](https://help.nextcloud.com/t/auto-copy-files-on-folder-creation/242382/4 "2026-03-26T09:28:21Z")

</div>

> [@bb77](#):
>
> you could also try restricting the `occ files:scan` command to a specific path

example:

`occ files:scan --all --home-only` restricting local files path and ignoring external files

---

<div class="post-metadata">

**Author:** ![bb77](https://help.nextcloud.com/letter_avatar/bb77/32/6_22734026db12803ebb3e059622ac3534.png) [@bb77](https://help.nextcloud.com/u/bb77)\
**Post date:** [March 26, 2026, 9:45am UTC](https://help.nextcloud.com/t/auto-copy-files-on-folder-creation/242382/5 "2026-03-26T09:45:21Z")

</div>

I just found out that there’s a specific command called `groupfolders:scan` that might be better suited for the OP’s use case.

@dolphinscorp See here: [GitHub - nextcloud/groupfolders: 📁👩‍👩‍👧‍👦 Admin-configured folders shared by everyone in a group or team. https://github.com/nextcloud-releases/groupfolders · GitHub](https://github.com/nextcloud/groupfolders#commands-available)

> `occ groupfolders:scan <folder_id>` → trigger a filescan for a Team folder

---

<div class="post-metadata">

**Author:** ![dolphinscorp](https://help.nextcloud.com/letter_avatar/dolphinscorp/32/6_22734026db12803ebb3e059622ac3534.png) [@dolphinscorp](https://help.nextcloud.com/u/dolphinscorp)\
**Post date:** [March 26, 2026, 11:39am UTC](https://help.nextcloud.com/t/auto-copy-files-on-folder-creation/242382/6 "2026-03-26T11:39:27Z")

</div>

Actually i am already using this

`$OCC groupfolders:scan $FOLDER_ID >/dev/null 2>&1`

But delay is around 18 seconds in showing files and folder in Nextcloud GuI

This is my full script

```auto
#!/bin/bash

while true; do
# Your actual script logic below
/usr/local/bin/nextcloud-folder-auto-setup.sh >> /var/log/nextcloud-folder-setup.log 2>&1

sleep 30

done
root@ubuntu-server:/usr/local/bin# cat nextcloud-folder-auto-setup2.sh
#!/bin/bash

while true; do
# Your actual script logic below
/usr/local/bin/nextcloud-folder-auto-setup-archive.sh >> /var/log/nextcloud-folder-setup-archive.log 2>&1

sleep 30

done
root@ubuntu-server:/usr/local/bin# cat nextcloud-folder-auto-setup.sh
#!/bin/bash

NEXTCLOUD_PATH=“/var/www/html/nextcloud”
ORDERS_PATH=“/var/www/html/data/__groupfolders/1”
TEMPLATE=“/var/www/html/data/admin/files/TemplatesCustom/TemplatesMain/.”
TEMPLATEUS=“/var/www/html/data/admin/files/TemplatesCustom/TemplatesForTeamUS/.”
TEMPLATECN=“/var/www/html/data/admin/files/TemplatesCustom/TemplatesForTeamCN/.”
OCC=“sudo -u www-data php $NEXTCLOUD_PATH/occ”
FOLDER_ID=1

cd “$NEXTCLOUD_PATH” || exit 1

for order in “$ORDERS_PATH”/*; do
[-d “$order”] || continue
base=$(basename “$order”)

if [-d "$order/Team US"] && [-d "$order/Team CN"]; then
    continue
fi

echo "Setting up structure in: $base"

# Create folders
mkdir -p "$order/Team US" "$order/Team CN"

# Copy templates
cp -a "$TEMPLATE" "$order/"
cp -a "$TEMPLATEUS" "$order/Team US/"
cp -a "$TEMPLATECN" "$order/Team CN/"

# Ownership
chown -R www-data:www-data "$order"

# Scan groupfolder so Nextcloud indexes the new content
echo "Scanning groupfolder..."
$OCC groupfolders:scan $FOLDER_ID >/dev/null 2>&1

# Wait until Team US and Team CN are visible to Nextcloud
echo "Waiting for Nextcloud to recognize new paths..."
ready=0
for i in {1..30}; do
    output=$($OCC groupfolders:permissions $FOLDER_ID --group "admin" "/$base/Team US" -- +read 2>&1)
    if [["$output" != *"Path not found in folder"*]]; then
        # revert test permission properly after path exists
        $OCC groupfolders:permissions $FOLDER_ID --group "admin" "/$base/Team US" -- +read +write +create +delete +share >/dev/null 2>&1
        ready=1
        echo "Paths are now recognized."
        break
    fi
    sleep 1
done

if ["$ready" -ne 1]; then
    echo "ERROR: Nextcloud still does not recognize /$base/Team US after waiting. Skipping permissions for $base"
    continue
fi

# Apply permissions
# US Team
$OCC groupfolders:permissions $FOLDER_ID --group "US Team" "/$base" -- +read -delete +write +create +share
$OCC groupfolders:permissions $FOLDER_ID --group "US Team" "/$base/Team US" -- +read +delete +write +create +share
$OCC groupfolders:permissions $FOLDER_ID --group "US Team" "/$base/Team CN" -- -read

# CN Team
$OCC groupfolders:permissions $FOLDER_ID --group "CN Team" "/$base" -- +read +write +create +share -delete
$OCC groupfolders:permissions $FOLDER_ID --group "CN Team" "/$base/Team CN" -- +read +delete +write +create +share
$OCC groupfolders:permissions $FOLDER_ID --group "CN Team" "/$base/Team US" -- -read

# Admin
$OCC groupfolders:permissions $FOLDER_ID --group "admin" "/$base" -- +read +write +create +delete +share
$OCC groupfolders:permissions $FOLDER_ID --group "admin" "/$base/Team US" -- +read +write +create +delete +share
$OCC groupfolders:permissions $FOLDER_ID --group "admin" "/$base/Team CN" -- +read +write +create +delete +share

echo "Completed: $base"

done

```

I have been asked to zero the delay, current delay is 18 seconds around to display files in nextcloud gui

---

<div class="post-metadata">

**Author:** ![system](https://help.nextcloud.com/user_avatar/help.nextcloud.com/system/32/29333_2.png) [@system](https://help.nextcloud.com/u/system)\
**Post date:** [June 23, 2026, 5:49pm UTC](https://help.nextcloud.com/t/auto-copy-files-on-folder-creation/242382/7 "2026-06-23T17:49:46Z")

</div>

This topic was automatically closed after 90 days. New replies are no longer allowed.
