1
0
mirror of https://github.com/PDP-10/its.git synced 2026-04-28 21:08:01 +00:00

Added tool to create timestamps.txt fragment from directory.

This is intended to be used on a directory containing ITS directories.
It recursively walks the tree and generates timestamps entries for
each file based on the file creation date/times.
This commit is contained in:
Eric Swenson
2023-03-07 13:19:52 -08:00
parent 2e6654e149
commit 870ce65b6e
7 changed files with 152 additions and 0 deletions

View File

@@ -0,0 +1,67 @@
import java.io._
import java.nio.file._
import java.nio.file.attribute._
import java.nio.file.FileVisitResult._
import java.nio.file.FileVisitOption._
import java.nio.file.Files
import java.nio.file.FileSystems
import java.nio.file.Path
import java.nio.file.StandardCopyOption._
import scala.io.Source
import scala.language.postfixOps
import scala.util.Try
import java.time.ZonedDateTime
import java.time.format.DateTimeFormatter
import java.time.ZoneId
import java.time.LocalDateTime
import java.util.TimeZone
import java.util.Locale
import java.time.Instant
import java.util.Calendar
import java.time.ZoneOffset
class Finder(showDirs: Boolean, prefix: String) extends SimpleFileVisitor[Path] {
val format = DateTimeFormatter.ofPattern("yyyyMMddHHmm.ss")
val now: Calendar = Calendar.getInstance()
val timeZone: TimeZone = now.getTimeZone()
val cal: Calendar = Calendar.getInstance(timeZone, Locale.US)
override def visitFile(file: Path, attrs: BasicFileAttributes): FileVisitResult = {
if (attrs.isRegularFile) {
val absolutePath = file.toAbsolutePath.toString
val pathToPrint = absolutePath.replace(prefix, "")
val attrs = Files.readAttributes(file, classOf[BasicFileAttributes])
val creationDate = attrs.creationTime()
cal.setTimeInMillis(creationDate.toMillis)
val dstOffset = cal.get(Calendar.DST_OFFSET)
val adjustedCreationDate = dstOffset match {
case 0 =>
creationDate.toMillis()
case 3600000 =>
creationDate.toMillis() + dstOffset
case _ =>
creationDate.toMillis()
}
val ldt: LocalDateTime = LocalDateTime.ofEpochSecond(adjustedCreationDate / 1000, 0, ZoneOffset.ofTotalSeconds(cal.get(Calendar.ZONE_OFFSET) / 1000))
System.out.println(s"${pathToPrint} ${ldt.format(format)}")
}
return CONTINUE
}
override def preVisitDirectory(dir: Path, attrs: BasicFileAttributes): FileVisitResult = {
if (showDirs)
println(s"Processing directory: ${dir.toAbsolutePath()}")
return CONTINUE
}
override def visitFileFailed(file: Path, ioe: IOException): FileVisitResult = {
System.err.println(ioe)
return CONTINUE
}
def done() = {
}
}

View File

@@ -0,0 +1,18 @@
import java.nio.file._
object GetItsDates extends App {
if (this.args.size != 2) {
println(s"Syntax is:")
println(s" get-its-datess <root directory> <prefix>")
}
else {
val rootDir = this.args(0)
val prefix = this.args(1)
val finder = new Finder(false, prefix)
Files.walkFileTree(
Paths.get(rootDir),
finder
)
finder.done()
}
}