首页 > 其他分享 >go判断远程文件是否存在RemoteFileExist

go判断远程文件是否存在RemoteFileExist

时间:2023-03-18 15:12:20浏览次数:43  
标签:aa err filepath strings go data 远程 RemoteFileExist

func IsFileExist(filepath string) bool {
// 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
}

标签:aa,err,filepath,strings,go,data,远程,RemoteFileExist
From: https://www.cnblogs.com/cheyunhua/p/17230670.html

相关文章