5 // FileUtil is a struct of File utility
10 // IsExists if file or directory exist
11 func IsExists(path string) bool {
12 _, err := os.Stat(path)
13 if err != nil && !os.IsExist(err) {
19 // IfNoFileToCreate if the file is not exist, create the file
20 func IfNoFileToCreate(fileName string) (file *os.File) {
23 if !IsExists(fileName) {
24 f, err = os.Create(fileName)
33 // PathExists return if path exists
34 func PathExists(path string) (bool, error) {
35 _, err := os.Stat(path)
43 // RemoveLocal deletes file
44 func (f *FileUtil) RemoveLocal(filename string) error {
45 return os.Remove(f.LocalDir + "/" + filename)
48 // BlockDirInitial initializes the blocks directory
49 func (f *FileUtil) BlockDirInitial() error {
50 ifPathExist, err := PathExists(f.LocalDir)
56 err = os.RemoveAll(f.LocalDir)
62 err = os.Mkdir(f.LocalDir, 0755)