@@ -2,24 +2,44 @@ package main
22
33import (
44 "io/ioutil"
5+ "log"
56 "os"
67 "path/filepath"
78
89 "github.com/CorentinB/DeepSort/pkg/logging"
910 filetype "gopkg.in/h2non/filetype.v1"
1011)
1112
12- func runRecursively (arguments * Arguments ) ([]string , error ) {
13- searchDir := arguments .Input
13+ func run (arguments * Arguments ) {
14+ f , err := os .Open (arguments .Input )
15+ if err != nil {
16+ log .Fatal (err )
17+ }
18+ files , err := f .Readdir (- 1 )
19+ f .Close ()
20+ if err != nil {
21+ logging .Error ("Unable to process this directory." , "[" + arguments .Input + "]" )
22+ os .Exit (1 )
23+ }
24+
25+ for _ , file := range files {
26+ path := arguments .Input + "/" + file .Name ()
27+ buf , _ := ioutil .ReadFile (path )
28+ if filetype .IsImage (buf ) {
29+ googleNetClassification (path , arguments )
30+ }
31+ }
32+ }
1433
34+ func runRecursively (arguments * Arguments ) ([]string , error ) {
1535 fileList := make ([]string , 0 )
16- e := filepath .Walk (searchDir , func (path string , f os.FileInfo , err error ) error {
36+ e := filepath .Walk (arguments . Input , func (path string , f os.FileInfo , err error ) error {
1737 fileList = append (fileList , path )
1838 return err
1939 })
2040
2141 if e != nil {
22- logging .Error ("Unable to process this directory." , "[" + searchDir + "]" )
42+ logging .Error ("Unable to process this directory." , "[" + arguments . Input + "]" )
2343 os .Exit (1 )
2444 }
2545
0 commit comments