I’m still very new to scala and I’m trying to copy a word document from one directory to another. I did some research online and could find nothing on how to do this in scala. I found a couple of comments in 2009 that said something to like “A comprehensive IO library is being developed in the scala incubator” and since it’s now 2013 I thought I’d find something but didn’t. I found several recommendations for using the org.apache.commons.io.FileUtils with java, so I thought I’d try it, even though I’m not a java programmer. I want to do something like:
import java.io.File
import java.io.IOException
import org.apache.commons.io.FileUtils
val srcDocx = "Template.docx"
val destDocx = new File("August.docx")
try {
FileUtils.copyDirectory(srcDocx, destDocx);
}
catch (IOException e) {
println("Failed to copy August.docx")
}
I could find nothing online about how to “install” the apache commons so that scala could find them.
Is there a better way to do this with scala than using the apache commons io fileutilities?
If not, can someone point me to what I need to do so the import org.apache.commons.io.FileUtils will work?
Also, I’m interested in making minor changes to my template.docx (which is a MS word document) and I see that working with xml is covered further along in Scala for the impatient. I did a quick search online, but didn’f find anthing. I was wondering if anyone can point me to some pointers there. I just want to do simple things like string replacement.
Thanks,
Mike Shields
--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-user+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Vlad,
I’m not using either yet since I’m just writing scala scripts and simple single file applications. I will use sbt eventually, but I’m trying to learn scala first.
Mike
Rodrigo,
Thanks for the tip. I looked at the java.nio.file api and it looks like the copy method is what I need, but I can’t get it to work. Since I’m not coming to Scala from java, it’s probably something stupid, but don’t know how to cast a string into a path. Here is what I tried:
val srcDocx : Path = "Template.docx"
val destDocx : Path = "August.docx"
java.nio.file.copy(srcDocx,destDocx)
Thanks,
Mike
In trying to find a solution to this, I ran across using sys.process._ to run system commands so I tried
import sys.process._
val srcDocx = "Template.docx"
val destDocx = "August.docx"
val result = ("copy " + srcDocx + " " + destDocx)!
But this doesn’t seem to work. In messing around in the REPL on windows 7 I can’t get any command to work and I get an error each time that the file can’t be found where the file is the command. When I make a script and use the –feature command, I get the warning that I need to enable the postfix operator !:
C:\scala\LearningScala\test.scala:9: warning: postfix operator ! should be enabled by making the implicit value scala.language.postfixOps visible. This can be achieved by adding the import clause 'import scala.language.postfixOps'
So I added that import to the script, but then I get an error that ! is not a member of String.
Any hints on what to do to execute system commands on windows 7?
Thanks,
Mike