How to move file/files from one folder to another in Scala

后端 未结 3 971
野的像风
野的像风 2021-01-21 02:54

I am new to Scala.

I\'ve Googled a lot on how to move files in Scala, but have only found how to move files in Java. I tried to move files using Java import Java.io

3条回答
  •  情书的邮戳
    2021-01-21 03:48

    os-lib makes it easy to copy files from one directory to another:

    os.list(os.pwd/"public").map(os.move.into(_, os.pwd/"pub2"))
    

    The java.io and java.nio libraries are generally difficult to work with (although not that ugly for this particular operation). It's best to rely on os-lib for filesystem operations.

    os.move.into takes two arguments: the file that's being moved and the destination directory.

    This code is flexible and easily modifiable. You could easily update it to only move files with a certain file extension.

    See here for more info on how to use os-lib.

提交回复
热议问题