Android Question Getting Folders and Files from a Server

Discussion in 'Android Questions' started by johnB, May 10, 2015.

  1. johnB

    johnB Active Member Licensed User


    Is it possible under B4A to get the files and folders from a SERVER attached to a network

    The following code works for B4J but I can't get it working on B4A.

    Is there am import java or that is needed

    #If JAVA
        import*;  //.File;
        //import java.util.List;
        import java.util.regex.Matcher;
         import java.util.*;
             public static List<String> filesFound = new ArrayList<String>();
            public static List<String> dirsFound = new ArrayList<String>();
        public static String ListFiles(String pattern)
        // public static void main(String[] args)
             BA.Log("Path " + fname);
             BA.Log("Path 2 " + fnameA);
              String path = fnameA;
              String returnFiles = "";
             String returnDirs = "";
              String files;
              File folder = new File(path);
              File[] listOfFiles = folder.listFiles();
              for (int i = 0; i < listOfFiles.length; i++)
                   if (listOfFiles[i].isFile())
                       files = listOfFiles[i].getName();
                       if (files.endsWith(".jpg") || files.endsWith(".jpeg") || files.endsWith(".JPG") || files.endsWith(".png") || files.endsWith(".PNG"))
                      filesFound.add(files);            //fname.substring(fname.lastIndexOf("/")+1));
                      returnFiles = returnFiles + "," + files;
                else if (listOfFiles[i].isDirectory())
                    files = listOfFiles[i].getName();
                    returnDirs = returnDirs + "&" + files;
                    BA.Log("Directory " + listOfFiles[i].getName());
                 //return "Hello world from class!";
                 //return returnList;
            //return "Hello world from class!";
            return returnDirs + "&&&&" + returnFiles;

    #End if
    Thanks in advance
  2. Erel

    Erel Administrator Staff Member Licensed User

    (why do you need Java code for this in B4J?)

    There is no built-in support for SMB in Android. You will need to use the SMB library for this.
  3. johnB

    johnB Active Member Licensed User

    Thanks for prompt reply

    In answer to your first question, I couldn't get in working in B4A so I tried B4J because most of the examples you find thru searches are pure java code and more likely to work in B4J - they don't need special android imports and to make sure that it wasn't my java code that was wrong.

    I'll give the SMB library a try

    Thanks again
    Last edited: May 10, 2015