-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
56 lines (49 loc) · 1.06 KB
/
main.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
package main
import (
"fmt"
"os"
"os/exec"
"strings"
)
func handleFoundFile(ext, fileName string) error {
if ext == "mp4" {
return handleVideoFiles(fileName)
}
return nil
}
func handleVideoFiles(fileName string) error {
cmdToCopy := fmt.Sprintf("mv ./%s ./Videos", fileName)
err := exec.Command("/bin/sh", "-c", cmdToCopy).Run()
if err != nil {
return err
}
return nil
}
func main (){
// get user home directory
home , err := os.UserHomeDir()
if err != nil {
panic(err)
}
downloadsDir := fmt.Sprintf("%s/Downloads", home)
// switch to downloads folder
err = os.Chdir(downloadsDir)
if err != nil {
panic(err)
}
// get a list of all files in the downloads dir
files, err := os.ReadDir(".")
if err != nil {
panic(err)
}
for _, file := range files {
info , err := os.Stat(file.Name())
if err != nil {
fmt.Printf("\nThe error is: %+v",err)
}
brkdwn := strings.SplitAfter(info.Name(), ".")
fileExtension := brkdwn[len(brkdwn)-1]
handleFoundFile(fileExtension, info.Name())
// fmt.Printf("\n%+v", file.Info())
}
}