A user’s folder can easily be retrieved with
$currentDirectory = $this->rootFolder->getUserFolder($user->getUID())
after IRootFolder
and IUserSession
have been properly injected as dependencies.
A listing of the folder’s contents
$currentDirectory->getDirectoryListing()
will show the user’s files and folders as well as shared folders which the admin has made accessible for that user.
Now, changing the working directory from there can be done via
$subDirectory = $currentDirectory->search("myFolderName")[0]
.
However, the search()
method appears to work only with a normal user folder but not with a shared folder. In the latter case it returns an array of size 0, content null, end of story.
I managed to gain access to a shared folder by using the uid:
$sharedFoldersContent = $currentDirectory->getById(123)[0]->getDirectoryListing();
But this means that one would have to get the user’s directory, create a listing, loop over its items until its name matches the sought one, get this item’s ID and only then be able to access its contents. This surely is not the recommended way, is it?
Note: once inside the shared folder, search()
works again.