-
Notifications
You must be signed in to change notification settings - Fork 0
/
fileentry.go
51 lines (44 loc) · 1.01 KB
/
fileentry.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
package filemonitor
import (
"os"
"strings"
)
type FileEntry struct {
path string
name string
lastModified int64
length int64
exists bool
directory bool
}
func (this *FileEntry) Refresh() bool {
fileInfo, err := os.Stat(this.path)
if err != nil {
return true
}
oldLastModified := this.lastModified
oldLength := this.length
oldDirectory := this.directory
this.lastModified = fileInfo.ModTime().UnixNano()
this.length = fileInfo.Size()
this.directory = fileInfo.IsDir()
return oldLastModified != this.lastModified || oldLength != this.length || oldDirectory != this.directory
}
func (this FileEntry) Path() string {
return this.path
}
func (this FileEntry) Name() string {
return this.name
}
func (this FileEntry) Directory() bool {
return this.directory
}
func (this FileEntry) Level() int {
return len(strings.Split(this.path, "\\")) - 1
}
func (this FileEntry) Length() int64 {
return this.length
}
func (this FileEntry) LastModified() int64 {
return this.lastModified
}