github.com/swishcloud/filesync@v0.0.0-20231002120458-6ade2feed6f9/x/hide_linux.go (about)

     1  package x
     2  
     3  import (
     4  	"errors"
     5  	"os"
     6  	"path/filepath"
     7  	"strings"
     8  )
     9  
    10  func HideFile(path string) error {
    11  	if !PathExist(path) {
    12  		return errors.New("file or directory not exits")
    13  	}
    14  	if !strings.HasPrefix(filepath.Base(path), ".") {
    15  		err := os.Rename(path, "."+path)
    16  		if err != nil {
    17  			return err
    18  		}
    19  	}
    20  	return nil
    21  }
    22  
    23  func IsHidden(path string) (bool, error) {
    24  	if !PathExist(path) {
    25  		return false, errors.New("file or directory not exits")
    26  	}
    27  	return strings.HasPrefix(filepath.Base(path), "."), nil
    28  }