String sharedLocation = "\\\\hostname"
new File(sharedLocation).list() returns null. exists() returns false as well. I do not know if this is something related to permissions. I am running the script on Windows.
Instead when I open via Windows -> Run and type in \\hostname, the shared folders are listed as a part of auto-complete in the Run window drop down. Why can’t I do the same with my java/groovy script? Is there a way to do this?
EDIT: Pardon the typo. The backslash was already escaped.
The backslashes in your string resolve to
\hostname. If you want to get\\hostname, you must have two backslashes and escape them properlyFileis for existing files, but\\hostnameis not a file or directory, but only a part of it. When you use\\hostname\share, you canlist()all files in this share.For listing shares, you can look at this answer https://stackoverflow.com/a/8480995/1741542, which suggests using the The Java CIFS Client Library.
With
listRootsyou can see already mounted shares.