Reputation: 3009
I've created both a File and Files object in Java based on a UNC path. When I check to see if the object isDirectory, both classes return false:
sourceDirectory = new File( "\\\\mymachine\\test\\new\\" );
boolean b = sourceDirectory.isDirectory();
Path path = sourceDirectory.toPath();
boolean a = Files.isDirectory( path );
results: b=false and a=false
What do I need to do to have my UNC directory recognized as a directory by File and Files?
Upvotes: 0
Views: 311
Reputation: 10945
Actually you are doing that correctly, but your local test case is misleading you.
For a windows path on a network share, your code would work fine, but for a local
path on your computer, you still need to specify the drive letter:
File netDir = new File("\\\\usstll0032\\share\\drc"); // network drive
System.out.println(netDir.isDirectory()); // true
File badDir = new File("\\\\us39-0cmq142\\temp"); // my computer
System.out.println(badDir.isDirectory()); // false
File goodDir = new File("\\\\us39-0cmq142\\c$\\temp"); // my computer
System.out.println(goodDir.isDirectory()); // true
Upvotes: 1