1
public void checkfile (String serverName) throws Exception {
    if (serverName == null)
    serverName = "";
    System.out.println("IN Check file method");
    File folder = new File("D:\\MVXOUT412");     //Path on the server
    int count = 0;
    String abc;
    File[] files =  folder.listFiles();
    if (files != null) {
        System.out.println("IN IF method");
        for (int i=0;i<files.length ;i++) {
            count++;
            abc = files[i].getName();
            System.out.println("Number of files: " + count);
            System.out.println("Name of files: " + abc);
        }
    }
}

This code is showing only some files at path/folder on the server. Other files can't be viewed. Login and logout happens successfully.

Svante
  • 50,694
  • 11
  • 78
  • 122
  • 1
    You may find an answer here : http://stackoverflow.com/a/1846349/2500326 – Sw4Tish Aug 13 '13 at 08:08
  • 1
    Does your program run with sufficient permissions to access all files? Are the missing files just random or is there a pattern (such as all of them being system files)? – BambooleanLogic Aug 13 '13 at 08:09
  • sure these files are still there at the moment when the script runs? this looks just fine. Are they accessible? not-hidden, do you have access? btw. you make like to use a foreach loop :) – mikus Aug 13 '13 at 08:11
  • This is a detail but why do you use `i` and `count`? Why not just keep `count` and use an enhanced for ( `for(File file : files) {`? – C.Champagne Aug 13 '13 at 10:08

1 Answers1

0
 public void listFilesForFolder(final File folder) {
 for (final File fileEntry : folder.listFiles()) {
     if (fileEntry.isDirectory()) {
        listFilesForFolder(fileEntry);
    } else {
        System.out.println(fileEntry.getName());
    }
}
  }

   final File folder = new File("/home/you/Desktop");
 listFilesForFolder(folder);
Mohsin Shaikh
  • 494
  • 1
  • 4
  • 11
  • Yes I do have permissions and the files/folders are not hidden as well. Only 1 or 2 folders(names) are displayed and others are not dispalyed. The above code does not display any folders but the .bat files present. What I need is the no. of .log files at a particular location on the server. Please help. Thanks – user2677705 Aug 13 '13 at 08:33
  • Hi All, I understood where I am going wrong.I am getting the output i.e folder/directory structure present on my local machine.Hence the wrong results.Instead of that I need the files present on a RDC machine.Can anybody please help. Thanks in advance. – user2677705 Aug 13 '13 at 10:55