github.com/mutagen-io/mutagen@v0.18.0-rc1/pkg/filesystem/visibility_windows.go (about) 1 package filesystem 2 3 import ( 4 "fmt" 5 "syscall" 6 ) 7 8 // MarkHidden ensures that a path is hidden. 9 func MarkHidden(path string) error { 10 // Convert the path to UTF-16 encoding for the system call. 11 path16, err := syscall.UTF16PtrFromString(path) 12 if err != nil { 13 return fmt.Errorf("unable to convert path encoding: %w", err) 14 } 15 16 // Get the existing file attributes. 17 attributes, err := syscall.GetFileAttributes(path16) 18 if err != nil { 19 return fmt.Errorf("unable to get file attributes: %w", err) 20 } 21 22 // Mark the hidden bit. 23 attributes |= syscall.FILE_ATTRIBUTE_HIDDEN 24 25 // Set the updated attributes. 26 err = syscall.SetFileAttributes(path16, attributes) 27 if err != nil { 28 return fmt.Errorf("unable to set file attributes: %w", err) 29 } 30 31 // Success. 32 return nil 33 }