Skip to main content

Get Files List

Get Directory Content#

TBD

Cloudike files library consists of the following core components (Note: All components are singletons):

  • FilesManager - the main library manager. It handles initialization and logout methods. FileManager also provides access to other components of the library. You can access the FileManager instance via FilesManager.shared.
  • FileTreeBrowser - provides methods to monitor contents of the remote directories. You can access the instance via FilesManager.browser.
  • FileOperations - provides methods to perform a set of operations with files and directories, i.e. copy, move etc. You can access the instance via FilesManager.operations.
  • FileUploader - provides methods to control the upload queue to the cloud. You can access the instance via FilesManager.uploader.
  • FileDownloader - provides methods to control the download queue from the cloud. You can access the instance via FilesManager.downloader.

To perform operations with files or directories, you need to use the FileManager.shared.operations component. For example, if you need to copy a file, you call FilesManager.shared.operations.copy(fileItem, destPath) where fileItem is one of the file items emitted by the directory contents observable (for more info, see chapter Read Remote Directory).

Each operation returns a Completable which completes with FileItem when the operation is finished successfully. The Completable emits an error if the operation fails.

The following example demonstrates how to show the progress dialog while the file is being renamed. This operation results in the FileItem that contains a public hash:

clfm.operations.rename(fileItem: "oldName", newName: "newName")    .subscribe()    .disposed(by: disposeBag)

When the operation is in progress, the FileItem emitted by the directory contents observable contains non-nil in the operation property. For more info, see chapter Read Remote Directory.

Reading the contents of the remote directory is implemented as an Observable, which emits directory contents each time when one of the following is changed:

  • Directory content (local DB);
  • Operations;
  • Upload queue;
  • Download queue;

The directory contents are provided as a list of FileItems.

To subscribe to directory contents changes, you need to call: getDirectoryContentObservable() providing path and sort type as described below:

private let items = Variable<[FileItem]>([]) 
override func viewWillAppear(_ animated: Bool) {        super.viewWillAppear(animated)                clfm.browser.getDirectoryContentObservable(path, sortedBy: .nameAsc)            .subscribe(onNext: { [weak self] items in                print("subscribed items > \(items.count)")                self?.items.value = items            })            .disposed(by: disposeBag)                updateContent()    }
    private func updateContent() {        clfm.browser.reloadDirectoryContent(path)            .subscribe()            .disposed(by: disposeBag)    }

NOTE: Method subscribe() returns a disposable which must be disposed in order to unsubscribe from directory contents changes (for example, when the user changes the current directory).

Reload Directory Content#

To reload the remote directory contents, you need to call FilesManager.browser.reloadDirectoryContent(path) which starts reading remote directory contents and refreshing local DB. For convenience, this method returns a Completable which completes when the directory contents reload is finished.