---
name: "addWatchTargetRecursive"
section: "3"
platform: "linux"
package: "libkysdk-system"
version: "3.0.1.4-1"
release: "Arch Linux 2026-11-07"
platforms: ["linux"]
url: "https://carta.tech/man/addWatchTargetRecursive"
---

# addWatchTargetRecursive(3)

增加需要监听的文件路径，对于目录，默认启用递归监听子目录

## NAME

addWatchTargetRecursive - 增加需要监听的文件路径，对于目录，默认启用递归监听子目录

## SYNOPSIS

```
#include <libkyfilewatcher.hpp>

```

### Classes

class **KYSDK\_FILEWATCHER::FileWatcher**

### Functions

QStringList addWatchTargetRecursive(QString url, FileWatcherType type = PERIODIC, int attr = OPEN\|CLOSE\|MODIFY\|DELETE, int maxdepth = 5, int recurType = DIR\|REGULAR);

Link with *-lkyfilewatcher*.

## Detailed Description

The main function of the interface is to add file paths that need to be listened to, and for directories, recursive listening subdirectories are enabled by default.

The argument *url* is the file path.

The argument *type* is the file watcher type，which is an enumeration type. The content is as follows:

    enum FileWatcherType{\
         ONESHOT = 0,    // 仅报送一次事件。请注意事件发生后，监听符号会从监听列表中移除，下次再用需要重新add\
         PERIODIC,\
         NEVER\
     };

The argument *attr* is the file watcher attribute，which is an enumeration type. The content is as follows:

    enum FileWatcherAttribute{\
         ACCESS = IN\_ACCESS,\
         CREATE = IN\_CREATE,\
         MODIFY = IN\_MODIFY,\
         DELETE = IN\_DELETE \| IN\_DELETE\_SELF,\
         ATTRIB = IN\_ATTRIB,\
         MOVE   = IN\_MOVE \| IN\_MOVE\_SELF,\
         OPEN   = IN\_OPEN,\
         CLOSE  = IN\_CLOSE,\
         ALL = IN\_ALL\_EVENTS\
     };

The argument *maxdepth* is the maximum depth specified for traversal search.

The argument *recurType* is the recursive type，which is an enumeration type. The content is as follows:

    enum RecursiveType{\
         DIR = 1 \<\< 0,\
         REGULAR = 1 \<\< 1,\
         HIDDEN = 1 \<\< 2,\
         TMPFILE = 1 \<\< 3,    //认为那些以~开头的是临时文件\
         ALLFILE = HIDDEN \| TMPFILE \| DIR \| REGULAR\
     };

## RETURN VALUE

## EXAMPLES

```
#include <QCoreApplication>
#include <QDebug>
#include "libkyfilewatcher.hpp"
using namespace KYSDK_FILEWATCHER;
int main(int argc, char *argv[])
{
    KYSDK_FILEWATCHER::FileWatcher watcher;
    watcher.addWatchTargetRecursive("/home/kylin/", PERIODIC, ALL, 3, REGULAR);
    getchar();
//    qDebug() << "update attr test";
//    watcher.updateWatchTargetAttribute("/data/testcode/test.c", DELETE);
//    getchar();
//    qDebug() << "re-add test";
//    watcher.addWatchTarget("/data/testcode/test.c", PERIODIC, ALL);
//    getchar();
//    qDebug() << "update oneshot test";
//    watcher.updateWatchTargetType("/data/testcode/test.c", ONESHOT);
//    getchar();
//    qDebug() << "remove target test";
//    watcher.removeWatchTarget("/data/testcode/test.c");
//    getchar();
    watcher.clearWatchList();
    return 0;
}
```

## CONFORMING TO

These functions are as per the withdrawn POSIX.1e draft specification. The following functions are Linux extensions: **addWatchTargetListRecursive**(), **removeWatchTargetRecursive**(), **clearWatchList**(), **pauseWatcher**() and **restartWatcher**().

## SEE ALSO

[**addWatchTargetListRecursive**(3)](/man/addWatchTargetListRecursive/3.md), [**removeWatchTargetRecursive**(3)](/man/removeWatchTargetRecursive/3.md), [**clearWatchList**(3)](/man/clearWatchList/3.md), [**pauseWatcher**(3)](/man/pauseWatcher/3.md) and [**restartWatcher**(3)](/man/restartWatcher/3.md).
