-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathfiles.go
More file actions
39 lines (36 loc) · 1021 Bytes
/
Copy pathfiles.go
File metadata and controls
39 lines (36 loc) · 1021 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package main
import (
"errors"
"io/ioutil"
"os"
"path/filepath"
"strings"
)
func readDirectory(currentDirectory string, targetDirectory string) ([]picture, error) {
var pictures []picture
//Get list of files
files, err := ioutil.ReadDir(currentDirectory)
if err != nil {
return pictures, err
}
//Prepare slice of pictures
for _, file := range files {
var fullSourcePath = filepath.Join(currentDirectory, file.Name())
var fullTargetPath = filepath.Join(targetDirectory, file.Name())
var extension = strings.ToLower(filepath.Ext(file.Name()))
var temp rgbHistogram
if extension == ".jpg" || extension == ".png" {
pictures = append(pictures, picture{fullSourcePath, fullTargetPath, temp, temp})
}
}
if len(pictures) < 1 {
return pictures, errors.New("the source directory does not contain any compatible images (JPG or PNG)")
}
return pictures, nil
}
func testForDirectory(directory string) bool {
if _, err := os.Stat(directory); os.IsNotExist(err) {
return false
}
return true
}