Scala - Get files based on name pattern -


i filter files based on patterns :

 - team_*.txt (e.g.: team_orlando.txt);  - name.*.city.txt (e.g.: name.robert.california.txt); 

or name (the pattern * . * - has spaces because broken text).

all filters come database table , dynamic.

i'm trying avoid use commands cp or mv. possible filter files using patterns above ?

here i've tried got regex error:

  def getfiles(dir:file, filter:string) = {                                                (dir.isdirectory, dir.exists) match {                                                    case (true, true) =>                                                                     dir.listfiles.filter(f => f.getname.matches(filter))                                 case _ =>                                                                                array[file]()                                                                      }                                                                                    }                                                                                    

you can use java.nio files.newdirectorystream() that, accept pattern in desired format:

val stream = files.newdirectorystream(dir, pattern) 

check http://docs.oracle.com/javase/tutorial/essential/io/dirs.html#glob detailed description.


Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -