创建了一个火绒自定义防护规则,保护文件夹,但是未生效,folder-reader.exe 是自己用 go 写的,另外测试了保护单文件是可以的
完整代码:
package main
import (
"bufio"
"fmt"
"io/ioutil"
"os"
"os/signal"
"runtime"
"strings"
"syscall"
)
/**
* 读入输入
*/
func readPrint() (bool, string) {
fmt.Println("input file path:")
inputReader := bufio.NewReader(os.Stdin)
input, err := inputReader.ReadString('\n')
if err != nil {
errInfo := fmt.Sprintf("read input error: \n%s\n", err.Error())
fmt.Printf(errInfo)
return false, ""
}
input = strings.ReplaceAll(input, "\r", "")
input = strings.ReplaceAll(input, "\n", "")
return true, input
}
/**
* 读取文件
*/
func fileRead(path string) {
exists, err := pathExists(path)
if err != nil {
errInfo := fmt.Sprintf("path check error: \n%s\n", err.Error())
fmt.Printf(errInfo)
return
}
if !exists {
errInfo := fmt.Sprintf("path not exists: \n%s\n", path)
fmt.Printf(errInfo)
return
}
if !isFile(path) {
errInfo := fmt.Sprintf("path is folder : \n%s\n", path)
fmt.Printf(errInfo)
return
}
file, err := os.Open(path)
if err != nil {
errInfo := fmt.Sprintf("fild open error: \n%s\n", err.Error())
fmt.Printf(errInfo)
return
}
content, err := ioutil.ReadAll(file)
if err != nil {
errInfo := fmt.Sprintf("fild read error: \n%s\n", err.Error())
fmt.Printf(errInfo)
return
}
outInfo := fmt.Sprintf("fild content: \n%s\n", content)
fmt.Printf(outInfo)
}
/**
* 判断所给路径文件 /文件夹是否存在
*/
func pathExists(path string) (bool, error) {
_, err := os.Stat(path)
if err == nil {
return true, nil
}
if os.IsNotExist(err) {
return false, nil
}
return false, err
}
/**
* 判断所给路径是否为文件夹
*/
func isDir(path string) bool {
s, err := os.Stat(path)
if err != nil {
return false
}
return s.IsDir()
}
/**
* 判断所给路径是否为文件
*/
func isFile(path string) bool {
return !isDir(path)
}
func main() {
succeed, input := readPrint()
if succeed {
fileRead(input)
}
if runtime.GOOS == "windows" {
//pause
fmt.Println("system(pause)")
quit := make(chan os.Signal)
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
sig := <-quit
for {
if sig.String() == "interrupt" {
break
}
}
}
}