Android Question Getting Folders and Files from a Server

johnB

Active Member
Licensed User
Hi

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 import.android.java that is needed

B4X:
#If JAVA
    import java.io.*;  //.File;
    //import java.util.List;
    //import java.net.URL;
    //import java.net.URLEncoder;
    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;
                  BA.Log(files);
            }
            }
            else if (listOfFiles[i].isDirectory())
            {
                files = listOfFiles[i].getName();
                dirsFound.add(files);
                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
 

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:
Top