-1

I am trying to recursively list a directory under a UNC Path. My code works with regular local directories.

I have tried many uri formats and many API call combinations ie.

    String url = "\\\\xxx.xxx.xx.xxx\\04_TRANSFER\\Edgar\\Folder_Sync_Test";
    String url2 = "file://xxx.xxx.xx.xxx/04_TRANSFER/Edgar/Folder_Sync_Test";
    String url3 = "file:////xxx.xxx.xx.xxx/04_TRANSFER/Edgar/Folder_Sync_Test";

    UNCTest test = new UNCTest();
    File f = new File(url);
    System.out.println("============================================");
    try {
        Files.walkFileTree(f.toPath(), test);
    } catch (Exception e) {
        System.out.println(e.getMessage());
    }
    System.out.println("============================================");
    try {
        Files.walkFileTree(Paths.get(URI.create(url2)), test);
    } catch (Exception e) {
        System.out.println(e.getMessage());
    }
    System.out.println("============================================");
    try {
        Files.walkFileTree(Paths.get(URI.create(url3)), test);
    } catch (Exception e) {
        System.out.println(e.getMessage());
    }

However all I get are MalformedUrlException(s) or simply \xxx.xxx.xxx.xxx\04_TRANSFER\Edgar\Folder_Sync_Test: Der Netzwerkname wurde nicht gefunden. (Networkname/path path not found).

I am beginning to wonder if it's even possible to do what I want here?

PS. the "test" class here simply extends SimpleFileVisitor

3 Answers3

0

The format of your first String url is correct. You are correctly escaping the backslashes.

It is a little challenging trying to debug an issue that is probably environment related.

Perhaps try creating a UNC share off your local machine and then point this application to it as a test.

If that works then perhaps your problem is related to permissions. Double-check that the user executing the Application has the appropriate permissions on the UNC file share.

Kyle Anderson
  • 6,801
  • 1
  • 29
  • 41
0

If an user is able to list the directory on the network share with

dir \\xxx.xxx.xx.xxx\04_TRANSFER\Edgar\Folder_Sync_Test

The following must work also for the same user

File url = new File("\\\\xxx.xxx.xx.xxx\\04_TRANSFER\\Edgar\\Folder_Sync_Test");
File[] listFiles = url.listFiles();
// Files.walkFileTree(url.toPath(), fileVisitor);

File url2 = new File("//xxx.xxx.xx.xxx/04_TRANSFER/Edgar\Folder_Sync_Test");
File[] listFiles = url2.listFiles();
// Files.walkFileTree(url2.toPath(), fileVisitor);

If url.listFiles() is working, then probably the error is in your UNCTest class.

SubOptimal
  • 22,518
  • 3
  • 53
  • 69
0

Ok, so the problem was in the Network.