I'm trying to use File.getTotalSpace()
and File.getFreeSpace()
on a NAS share via UNC, from a Windows host.
Due to the various links in the NAS, the free/total space will be different based on the specific directory requested.
For example, in a DOS box:
dir \\nas\level1
might return 12,234,567 bytes free, but:
dir \\nas\level1\level2\level3
returns 987,654,321 bytes free.
I try:
new File("\\\\nas\\level1\\level2\\level3").getFreeSpace();
but this returns 12,234,567. It appears that getFreeSpace()
and getTotalSpace()
are retrieving the reported space from the root of the path (\\nas, in this case), rather than from the level I requested.
If I map that UNC path to a drive letter, e.g.:
net use s: \\nas\level1\level2\level3
then
new File("s:").getFreeSpace();
will return the correct value. But I have to iterate through a bunch of UNC paths, so mapping them all is not feasible.
So how can I get the free/total space of a UNC-based share from the specific directory level I'm requesting?