apoc.load.directory.async.add

Procedure APOC Full

apoc.load.directory.async.add(name, cypher, pattern, urlDir, {}) YIELD name, status, pattern, cypher, urlDir, config, error - Adds or replaces a folder listener with a specific name, which is triggered for all files with the given pattern and executes the specified Cypher query when triggered. Returns a list of all listeners. It is possible to specify the event type in the config parameter.

Signature

apoc.load.directory.async.add(name :: STRING?, cypher :: STRING?, pattern = * :: STRING?, urlDir =  :: STRING?, config = {} :: MAP?) :: (name :: STRING?, status :: STRING?, pattern :: STRING?, cypher :: STRING?, urlDir :: STRING?, config :: MAP?, error :: STRING?)

Input parameters

Name Type Default

name

STRING?

null

cypher

STRING?

null

pattern

STRING?

*

urlDir

STRING?

config

MAP?

{}

Config parameters

The procedure supports the following config parameters:

Table 1. Config parameters
name type default description

interval

Integer

1000

Time interval in ms after re-watch for directory changes

listenEventType

List<Enum>

List.of("CREATE", "DELETE", "MODIFY")

Types of event that execute the cypher query, that is creation (CREATE), deletion (DELETE) or editing (MODIFY) of a file in specified folder

Output parameters

Name Type

name

STRING?

status

STRING?

pattern

STRING?

cypher

STRING?

urlDir

STRING?

config

MAP?

error

STRING?

Usage Examples

Additional information about the apoc.load.directory.async.add procedure parameters

  • The name parameter defines the name assigned to the trigger. If the name already exists, the existing trigger will be overwritten.

  • The cypher parameter should contain a Cypher query, which is executed when the trigger is activated.

  • The pattern parameter describes the files that should be considered by the trigger. The pattern supports '?' and '*' to represent single or multiple wildcard characters, see WildcardFileFilter - Apache Commons IO for more information. Default value: *

  • The urlDir parameter defined the directory watched for changes. Default value: empty String, which will observe the import directory

  • The config parameter allows additional configuration. Default value: {}

Additional Trigger Event Context Parameters known in the Cypher query

The Cypher query can have the following parameters giving additional context on the trigger event:

  • $fileName: the name of the file which triggered the event

  • $filePath: the absolute path of the file which triggered the event if apoc.import.file.use_neo4j_config=false, otherwise the relative path starting from $IMPORT_DIR

  • $fileDirectory: the absolute path directory of the file which triggered the event if apoc.import.file.use_neo4j_config=false, otherwise the relative path starting from $IMPORT_DIR

  • $listenEventType: the triggered event ("CREATE", "DELETE" or "MODIFY"). The event "CREATE" happens when a file is inserted in the folder, "DELETE" when a file is removed from the folder and "MODIFY" when a file in the folder is changed.

If a file is renamed, it will trigger 2 events, first "DELETE" and then "CREATE".