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

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?

1 Like

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

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:

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

I think that’s the easiest way to go :+1:

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 :+1:

Well, how?

Perhaps another way. I use an additional file uploader (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.

I think that’s the easiest way to go :+1:

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

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

There’s also a condition for file activity:
image

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

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.

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??

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