-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExtract.go
68 lines (52 loc) · 1.11 KB
/
Extract.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
package main
import (
"archive/zip"
"fmt"
"io"
"io/ioutil"
"os"
"path"
"regexp"
"strings"
)
func fname(s string) string {
Pat := strings.Split(s, "/")
Name := strings.Split(Pat[len(Pat)-1], ".")
return Name[0]
}
func openPPT(FName string) error {
fz, err := zip.OpenReader(FName)
if err != nil {
fmt.Println(err)
return err
}
defer fz.Close()
err = os.Mkdir(fname(FName), 0)
for _, file := range fz.File {
if m, _ := regexp.Match(`ppt/media/media[1234567890]*.m4a`, []byte(file.Name)); m {
fmt.Println(" - ", fname(file.Name))
ft, _ := file.Open()
fd, _ := os.Create(fname(FName) + "/" + fname(file.Name) + ".m4a")
io.Copy(fd, ft)
ft.Close()
fd.Close()
}
}
return nil
}
func main() {
if len(os.Args) > 1 {
for i := 1; i < len(os.Args); i++ {
openPPT(os.Args[1])
}
} else {
dir, _ := os.Getwd()
FL, _ := ioutil.ReadDir(dir)
for _, E := range FL {
if ext := path.Ext(E.Name()); ext == ".ppt" || ext == ".pptx" || ext == ".ppsx" || ext == ".pptm" || ext == ".potx" || ext == ".ppsm" || ext == ".pps" {
fmt.Println(E.Name())
openPPT(E.Name())
}
}
}
}