-
Notifications
You must be signed in to change notification settings - Fork 0
/
organizers.go
71 lines (56 loc) · 1.46 KB
/
organizers.go
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package main
import (
"fmt"
"io/ioutil"
"strings"
)
// List of organizers methods
const ALPHABETICAL_M = "alph"
const TYPE_M = "type"
const DATE_M = "date"
const EXTENSION_M = "ext"
const LOOKING_SAME = "same" // For future release
func OrganizeDir(
dirPath string,
ignoreFiles []string,
ignoresExt []string,
lang string,
method string) map[string][]string {
filesInfos, err := ioutil.ReadDir(dirPath)
if err != nil {
fmt.Println("Error while reading ", dirPath)
return nil
}
var ext string
var fileType FileType
var ftName string
var uName string
var firstL string
var dateStr string
var isIgnoreF bool
var isIgnoreE bool
organizer := make(map[string][]string)
for _, info := range filesInfos {
ext = GetFileExtension(info.Name())
isIgnoreF = Contains(info.Name(), ignoreFiles)
isIgnoreE = Contains(ext, ignoresExt)
if !info.IsDir() && !isIgnoreF && !isIgnoreE {
fileType = GetFileType(ext)
ftName = fileType.val(lang)
switch method {
case ALPHABETICAL_M:
uName = strings.ToUpper(info.Name())
firstL = string(uName[0])
organizer[firstL] = append(organizer[firstL], info.Name())
case DATE_M:
dateStr = strings.Split(info.ModTime().String(), " ")[0]
organizer[dateStr] = append(organizer[dateStr], info.Name())
case EXTENSION_M:
organizer[ext] = append(organizer[ext], info.Name())
default: //TYPE_M method
organizer[ftName] = append(organizer[ftName], info.Name())
}
}
}
return organizer
}