func IsFileExist(filepath string) bool {标签:aa,err,filepath,strings,go,data,远程,RemoteFileExist From: https://www.cnblogs.com/cheyunhua/p/17230670.html
// if remote file is
// ls -l | grep aa | wc -l
fileName := path.Base(filepath) // aa
fileDirName := path.Dir(filepath)
fileCommand := fmt.Sprintf("ls -l %s | grep %s | wc -l", fileDirName, fileName)
data := strings.Replace(String("/bin/sh", "-c", fileCommand), "\r", "", -1)
data = strings.Replace(data, "\n", "", -1)
count, err := strconv.Atoi(strings.TrimSpace(data))
defer func() {
if r := recover(); r != nil {
logger.Error("[os][%s]RemoteFileExist:%s", filepath, err)
}
}()
if err != nil {
panic(1)
}
return count != 0
}