title: Union Dataframes based on condition in spark(scala)
body: <p>I have a folder which consists of 4 subfolders which contains parquet files
  Folder->A.parquet,B.parquet,C.parquet,D.parquet(subfolders). My requirement is I want to union data frames based on file Names I provide to the method.
  I am doing it with code
  </p>
  
  <pre><code>val df = listDirectoriesGetWantedFile(folderPath,sqlContext,A,B)
  def listDirectoriesGetWantedFile(folderPath: String, sqlContext: SQLContext, str1: String, str2: String): DataFrame = {
      var df: DataFrame = null
      val sb = new StringBuilder
      sb.setLength(0)
      var done = false
      val path = new Path(folderPath)
      if (fileSystem.isDirectory(path)) {
          var files = fileSystem.listStatus(path)
          for (file &lt;- files) {
          if (file.getPath.getName.contains(str) &amp;&amp; !done) {
            sb.append(file.getPath.toString())
            sb.append(",")
            done = true
          } else if (file.getPath.getName.contains(str2)) {
            sb.append(file.getPath.toString())
          }
      }
  }
  </code></pre>
  
  <p>But I need to split the sb and then union the dataframes. Which I am unable to find the solution. How can I approach it and solve</p>