# Automatically do a files:scan on that specific file when a new file is added

**URL:** <https://help.nextcloud.com/t/automatically-do-a-files-scan-on-that-specific-file-when-a-new-file-is-added/95448>\
**Category:** ℹ️ Support\
**Tags:** flow-app\
**Created:** [October 17, 2020, 10:56am UTC](https://help.nextcloud.com/t/automatically-do-a-files-scan-on-that-specific-file-when-a-new-file-is-added/95448 "2020-10-17T10:56:49Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![alderson59](https://help.nextcloud.com/user_avatar/help.nextcloud.com/alderson59/32/30270_2.png) [@alderson59](https://help.nextcloud.com/u/alderson59)\
**Post date:** [October 17, 2020, 10:56am UTC](https://help.nextcloud.com/t/automatically-do-a-files-scan-on-that-specific-file-when-a-new-file-is-added/95448/1 "2020-10-17T10:56:49Z")

</div>

Hi, let’s say I have another app that generates files in the nextcloud directory “user/files/folder1/”, how can I get nextcloud to automate adding the new file into NC without having to type out the OCC command manually each time?

I currently normally run this with the occweb app  
`files:scan --path=user/files/folder1`  
Would usually run this instead of `files:scan --all` as it would take too long. Any alternate ways to add the file without scanning the whole folder would be even better!

I’m running NC20 on docker, using the latest image.

I note that there’s the workflow scripts app, and I also use rcdailey/nextcloud-cronjob. Any simple way to get the desired effect working?

---

<div class="post-metadata">

**Author:** ![devnull](https://help.nextcloud.com/user_avatar/help.nextcloud.com/devnull/32/27793_2.png) [@devnull](https://help.nextcloud.com/u/devnull)\
**Post date:** [October 17, 2020, 11:46am UTC](https://help.nextcloud.com/t/automatically-do-a-files-scan-on-that-specific-file-when-a-new-file-is-added/95448/2 "2020-10-17T11:46:22Z")

</div>

You can also scan for username . Perhaps path not works.

> **[Using the occ command — Nextcloud latest Administration Manual latest...](https://docs.nextcloud.com/server/20/admin_manual/configuration_server/occ_command.html#file-operations-label)**

---

<div class="post-metadata">

**Author:** ![MichaelJ\_McCarn](https://help.nextcloud.com/user_avatar/help.nextcloud.com/michaelj_mccarn/32/14912_2.png) [@MichaelJ\_McCarn](https://help.nextcloud.com/u/MichaelJ_McCarn)\
**Post date:** [October 17, 2020, 12:59pm UTC](https://help.nextcloud.com/t/automatically-do-a-files-scan-on-that-specific-file-when-a-new-file-is-added/95448/3 "2020-10-17T12:59:50Z")

</div>

If the folder is on a linux system you might be able to do what you want with ‘inotifywait’ as described in this stackoverflow post:

> <https://stackoverflow.com/questions/34957484/linux-watch-a-directory-for-new-files-then-run-a-script>

```
 inotifywait -m -e close_write /full/path/to/folder1/ | gawk '{print $1$3; fflush()}' | xargs -L 1 occ files:scan --path=path/to/folder1
```

---

<div class="post-metadata">

**Author:** ![j-ed](https://help.nextcloud.com/user_avatar/help.nextcloud.com/j-ed/32/7281_2.png) [@j-ed](https://help.nextcloud.com/u/j-ed)\
**Post date:** [October 17, 2020, 1:57pm UTC](https://help.nextcloud.com/t/automatically-do-a-files-scan-on-that-specific-file-when-a-new-file-is-added/95448/4 "2020-10-17T13:57:45Z")

</div>

> [@alderson59](#):
>
> I note that there’s the workflow scripts app

I think that’s the easiest way to go 👍

---

<div class="post-metadata">

**Author:** ![alderson59](https://help.nextcloud.com/user_avatar/help.nextcloud.com/alderson59/32/30270_2.png) [@alderson59](https://help.nextcloud.com/u/alderson59)\
**Post date:** [October 21, 2020, 8:35am UTC](https://help.nextcloud.com/t/automatically-do-a-files-scan-on-that-specific-file-when-a-new-file-is-added/95448/5 "2020-10-21T08:35:46Z")

</div>

> You can also scan for username . Perhaps path not works.

How does this help my situation? I already know how to scan for username…

> If the folder is on a linux system you might be able to do what you want with ‘inotifywait’ as described in this stackoverflow post:

Cool solution, but as I mentioned, I run my NC on docker. The change you advised won’t stand an update.

> I think that’s the easiest way to go 👍

Well, how?

---

<div class="post-metadata">

**Author:** ![devnull](https://help.nextcloud.com/user_avatar/help.nextcloud.com/devnull/32/27793_2.png) [@devnull](https://help.nextcloud.com/u/devnull)\
**Post date:** [October 21, 2020, 8:50am UTC](https://help.nextcloud.com/t/automatically-do-a-files-scan-on-that-specific-file-when-a-new-file-is-added/95448/6 "2020-10-21T08:50:44Z")

</div>

> [@alderson59](#):
>
> Hi, let’s say I have another app that generates files in the nextcloud directory “user/files/folder1/”, how can I get nextcloud to automate adding the new file into NC without having to type out the OCC command manually each time?

Perhaps another way. I use an additional file uploader ([https://tinyfilemanager.github.io/](https://tinyfilemanager.github.io/)) to upload to an external dir on the same server but outside Nextcloud. In Nextcloud i have mounted the external directory (not in nextcloud/data) with “external storage” (type local). If i upload files i found them after reload the folder in Nextcloud.

[https://docs.nextcloud.com/server/latest/admin\_manual/configuration\_files/external\_storage\_configuration\_gui.html](https://docs.nextcloud.com/server/latest/admin_manual/configuration_files/external_storage_configuration_gui.html)

[https://docs.nextcloud.com/server/latest/admin\_manual/configuration\_files/external\_storage/local.html](https://docs.nextcloud.com/server/latest/admin_manual/configuration_files/external_storage/local.html)

---

<div class="post-metadata">

**Author:** ![j-ed](https://help.nextcloud.com/user_avatar/help.nextcloud.com/j-ed/32/7281_2.png) [@j-ed](https://help.nextcloud.com/u/j-ed)\
**Post date:** [October 21, 2020, 9:09am UTC](https://help.nextcloud.com/t/automatically-do-a-files-scan-on-that-specific-file-when-a-new-file-is-added/95448/7 "2020-10-21T09:09:43Z")

</div>

> > I think that’s the easiest way to go 👍
> 
> Well, how?

Install the workflow\_scripts app, create a batch script which is being executed on a new file creation event and force an “`occ files:scan ...`” command. Other users have already used it for various jobs, see e.g.:

[https://help.nextcloud.com/search?q=workflow\_scripts%20%40j-ed%20](https://help.nextcloud.com/search?q=workflow_scripts%20%40j-ed%20)

---

<div class="post-metadata">

**Author:** ![alderson59](https://help.nextcloud.com/user_avatar/help.nextcloud.com/alderson59/32/30270_2.png) [@alderson59](https://help.nextcloud.com/u/alderson59)\
**Post date:** [October 21, 2020, 9:24am UTC](https://help.nextcloud.com/t/automatically-do-a-files-scan-on-that-specific-file-when-a-new-file-is-added/95448/8 "2020-10-21T09:24:37Z")

</div>

These are the options available to the workflow triggers. It does not have a “get newly added files” or a scheduler that I know of.

![image](https://help.nextcloud.com/uploads/default/original/3X/c/9/c99f9db37bd7ff5b0aee82c16f4cc9c34650bea4.png)

There’s also a condition for file activity:  
 ![image](https://help.nextcloud.com/uploads/default/original/3X/6/0/60500b38962ac440642f8433f77e547658a2f52e.png)

But as I understand it, it refers to files being created legitimately via the web interface, or am I missing something here? 🙂

---

<div class="post-metadata">

**Author:** ![j-ed](https://help.nextcloud.com/user_avatar/help.nextcloud.com/j-ed/32/7281_2.png) [@j-ed](https://help.nextcloud.com/u/j-ed)\
**Post date:** [October 21, 2020, 9:40am UTC](https://help.nextcloud.com/t/automatically-do-a-files-scan-on-that-specific-file-when-a-new-file-is-added/95448/9 "2020-10-21T09:40:56Z")

</div>

> [@alderson59](#):
>
> But as I understand it, it refers to files being created legitimately via the web interface, or am I missing something here?

That’s right, because this is the only case where Nextcloud is aware of file system changes. If you’re by-passing the Nextcloud gui you have to make sure that a file scan is triggered afterwards.

---

<div class="post-metadata">

**Author:** ![alderson59](https://help.nextcloud.com/user_avatar/help.nextcloud.com/alderson59/32/30270_2.png) [@alderson59](https://help.nextcloud.com/u/alderson59)\
**Post date:** [October 21, 2020, 12:37pm UTC](https://help.nextcloud.com/t/automatically-do-a-files-scan-on-that-specific-file-when-a-new-file-is-added/95448/10 "2020-10-21T12:37:40Z")

</div>

That’s exactly what I’m trying to achieve! So how to do this?

I feel like we’ve not gotten anywhere with the past few replies!

Was I not clear enough in my opening question??

---

<div class="post-metadata">

**Author:** ![devnull](https://help.nextcloud.com/user_avatar/help.nextcloud.com/devnull/32/27793_2.png) [@devnull](https://help.nextcloud.com/u/devnull)\
**Post date:** [October 21, 2020, 12:44pm UTC](https://help.nextcloud.com/t/automatically-do-a-files-scan-on-that-specific-file-when-a-new-file-is-added/95448/11 "2020-10-21T12:44:49Z")

</div>

Have you test my idea with external storage or why does it not makes sense for you?

---

<div class="post-metadata">

**Author:** ![Irdi](https://help.nextcloud.com/user_avatar/help.nextcloud.com/irdi/32/50042_2.png) [@Irdi](https://help.nextcloud.com/u/Irdi)\
**Post date:** [July 6, 2023, 3:19pm UTC](https://help.nextcloud.com/t/automatically-do-a-files-scan-on-that-specific-file-when-a-new-file-is-added/95448/12 "2023-07-06T15:19:19Z")

</div>

Old post but i just encountered this issue and ill share how i solved it.

Inside Nextcloud dir you run this command:

sudo -u www-data php occ files:scan --path=“user\_id/files/path”  
Example: sudo -u www-data php occ files:scan --path=“/alice/files/Music”

That scans the specific directory you want to scan.

You create a cron job to run each minute to scan the directory

\*/1 \* \* \* \* php8.1 -f /var/www/html/occ files:scan --path=“/alice/files/Music”

Do not forget to change the php version according to your installation and the path to you Nextcloud installation.

---

<div class="post-metadata">

**Author:** ![ChineseAegis](https://help.nextcloud.com/user_avatar/help.nextcloud.com/chineseaegis/32/53895_2.png) [@ChineseAegis](https://help.nextcloud.com/u/ChineseAegis)\
**Post date:** [August 20, 2023, 1:49pm UTC](https://help.nextcloud.com/t/automatically-do-a-files-scan-on-that-specific-file-when-a-new-file-is-added/95448/13 "2023-08-20T13:49:22Z")

</div>

I have solve this problem by writing an simple auto\_scan.sh.  
I use docker for nextcloud server,and when starting docker,i run this script at the same time.  
Here is the script

#!/bin/bash

DIRECTORY=“/root/data/docker\_data/nextcloud/data/data/lh”  
COMMAND=“sudo docker exec --user www-data nextcloud-app /var/www/html/occ files:scan lh”  
eval “$COMMAND”

# 监视文件夹变化

while inotifywait -r -e modify,create,delete “$DIRECTORY”  
do  
# 执行命令  
echo “文件夹发生变化，执行命令: $COMMAND”  
sleep 5  
eval “$COMMAND”  
done

change DIRECTORY and COMMAND to yours,and save it.  
run ./auto\_scan.sh and then it’s solved.  
if you want to put the program into the background,you can use the screen for it.

---

<div class="post-metadata">

**Author:** ![ChineseAegis](https://help.nextcloud.com/user_avatar/help.nextcloud.com/chineseaegis/32/53895_2.png) [@ChineseAegis](https://help.nextcloud.com/u/ChineseAegis)\
**Post date:** [August 20, 2023, 2:14pm UTC](https://help.nextcloud.com/t/automatically-do-a-files-scan-on-that-specific-file-when-a-new-file-is-added/95448/14 "2023-08-20T14:14:55Z")

</div>

oh,I just find another method to solve it.  
get to your config.php and add a new line like this:  
‘filesystem\_check\_changes’ =\> 1,  
1 represent checking any request to the folder and update it in nextcloud.  
0 represent doing nothing  
this method is such wonderful! it’s seem that i had wasted much time for writting a script

---

<div class="post-metadata">

**Author:** ![wwe](https://help.nextcloud.com/user_avatar/help.nextcloud.com/wwe/32/72963_2.png) [@wwe](https://help.nextcloud.com/u/wwe)\
**Post date:** [December 14, 2024, 3:54pm UTC](https://help.nextcloud.com/t/automatically-do-a-files-scan-on-that-specific-file-when-a-new-file-is-added/95448/15 "2024-12-14T15:54:39Z")

</div>


