package main

import (
  "fmt"
  "os"
  "path/filepath"

  "github.com/gmcnaughton/gofindhdr/findhdr"
)

func main() {
  inpath := "/Users/gmcnaughton/Pictures/Photos Library.photoslibrary/Masters/2017/02"
  // inpath := "./test"
  outpath := "./out"
  optlink := true

  // Create output folder
  _ = os.Mkdir(outpath, 0755)

  count := 0

  findhdr.Find(inpath, func(hdr *findhdr.Hdr) {
    for _, image := range hdr.Images() {
      count++

      link := filepath.Join(outpath, image.Info.Name())

      if optlink {
        fmt.Println("Linking", link)
        err := os.Link(image.Path, link)
        if os.IsExist(err) {
          fmt.Printf("Skipping %s (file exists)\n", link)
        } else if err != nil {
          fmt.Printf("Error linking %s\n", link)
          fmt.Println(err)
        }
      } else {
        fmt.Println(hdr)
      }
    }
    fmt.Println()
  })

  fmt.Printf("Found %d hdrs.\n", count)
}

package main

import (
  "fmt"
  "os"
  "path/filepath"

  "github.com/gmcnaughton/gofindhdr/findhdr"
)

func main() {
  // inpath := "/Users/gmcnaughton/Pictures/Photos Library.photoslibrary/Masters/2017/02"
  inpath := "./test"
  outpath := "./out"
  optlink := false

  // Create output folder
  if optlink {
    err := os.Mkdir(outpath, 0755)
    if err != nil && !os.IsExist(err) {
      fmt.Println("Error creating out directory", err)
    }
  }

  count := 0

  findhdr.Find(inpath, func(hdr *findhdr.Hdr) {
    count++

    if optlink {
      for _, image := range hdr.Images() {
        link := filepath.Join(outpath, image.Info.Name())
        fmt.Println("Linking", link)
        err := os.Link(image.Path, link)
        if os.IsExist(err) {
          fmt.Println("Skipping", err)
        } else if err != nil {
          fmt.Println("Error linking", err)
        }
      }
    } else {
      fmt.Println(hdr)
    }
  })

  fmt.Printf("Found %d hdrs.\n", count)
}

Support preview mode (don't link, just print matches found)
Support preview mode (don't link, just print matches found)
