Last active
July 31, 2018 17:25
-
-
Save Sciss/8043c206bc92aa47384100256ac6ffb5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys.process._ | |
def read(f: File): String = { | |
val fin = new java.io.FileInputStream(f) | |
try { | |
val sz = fin.available() | |
val arr = new Array[Byte](sz) | |
fin.read(arr) | |
new String(arr, "UTF-8") | |
} finally { | |
fin.close() | |
} | |
} | |
def run(dir: File, word: String = "swarm"): Unit = { | |
val f1 = dir.children(_.extL == "pdf").sorted(File.NameOrdering) | |
f1.foreach { f0 => | |
val tf = file("/data/temp/test.txt") | |
tf.delete() | |
val res = List("pdftotext", f0.path, tf.path).! | |
if (res == 0) { | |
val t = read(tf) | |
val i = t.toLowerCase.indexOf(word) | |
// val ok = if (i < 0) " " else "!!" | |
// println(s"$ok ${f0.name}") | |
if (i >= 0) println(f0.name) | |
} | |
} | |
} | |
val d0 = file("/data/texts/Papers") | |
run(d0 / "B") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Variant: