FileSystemWatcher QML Type

The FileSystemWatcher component provides an interface for monitoring files and directories for modifications. More...

Import Statement: import ArcGIS.AppFramework.Desktop 1.0

Properties

Signals

Methods

Detailed Description

The following code snippet demonstrates usage of the FileSystemWatcher component. Two file dialogs allow you to select files or folders to watch; after one has been selected, any changes to the paths of the file (or contained files) will be listed in the box labelled 'Changed paths'.

Item {
    property var changedPaths: []
    FileSystemWatcher {
        id: fileSystemWatcher
        paths: [
            "~"
        ]
       onFileChanged: {
            console.log("onFileChanged", path);
            changedPaths.unshift(new Date().toString() + ":" + path);
            changedPathsComboBox.refresh();
        }
        onFolderChanged: {
            console.log("onFolderChanged", path);
            changedPaths.unshift(new Date().toString() + ":" + path);
            changedPathsComboBox.refresh();
        }
    }
    Column {
        anchors {
            fill: parent
            margins: 10
        }
        spacing: 10
        Text {
            text: "Files being watched"
        }
        ComboBox {
            model: fileSystemWatcher.files
        }
        Button {
            text: "Add File"
            onClicked: {
                fileDialog.visible = true;
            }
        }
        Text {
            text: "Folders being watched"
        }
        ComboBox {
            model: fileSystemWatcher.folders
        }
        Button {
            text: "Add Folder"
            onClicked: {
                folderDialog.visible = true;
            }
        }
        Text {
            text: "Changed paths"
        }
        ComboBox {
            id: changedPathsComboBox
            width: parent.width
            model: changedPaths
            function refresh() {
                model = [];
                model = changedPaths;
            }
        }
    }
    FileDialog {
        id: fileDialog
        title: "Choose a file to watch"
        selectExisting: true
        nameFilters: [ "All files (*)" ]
        onAccepted: {
            fileSystemWatcher.addPath(fileUrl);
        }
    }
    FileDialog {
        id: folderDialog
        title: "Choose a folder to watch"
        selectExisting: true
        selectFolder: true
        nameFilters: [ "All files (*)" ]
        onAccepted: {
            fileSystemWatcher.addPath(fileUrl);
        }
    }
}

Property Documentation

[read-only] files : QStringList

Returns a list of paths to files that are being watched.


[read-only] folders : QStringList

Returns a list of paths to directories that are being watched.


paths : QStringList

Returns a list of files and directories currently being monitored. This list is the combined result of both the 'files' and 'folders' properties.


Signal Documentation

fileChanged(string path)

This signal is emitted when the file at the specified path is modified, renamed or removed from disk

Note: The corresponding handler is onFileChanged.


folderChanged(string path)

This signal is emitted when the folder at a specified path, is modified or removed from disk

Note: The corresponding handler is onFolderChanged.


Method Documentation

bool addPath(url pathUrl)

Adds path to the file system watcher.

The pathUrl parameter

The URL of the file you're adding.


bool addPath(string path)

Adds path to the file system watcher.

The path parameter

The path to the file you're adding.


clear()

Wipes the file system watcher of all paths currently being observed.


bool removePath(url pathUrl)

Removes the specified path from the file system watcher.

The pathUrl parameter

The URL of the path that you're removing.


bool removePath(string path)

Removes the specified path from the file system watcher.

The path parameter

A string version of the path that you're removing.


Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.