hidden_windows.go 815 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Copyright (C) 2014 Jakob Borg and Contributors (see the CONTRIBUTORS file).
  2. // All rights reserved. Use of this source code is governed by an MIT-style
  3. // license that can be found in the LICENSE file.
  4. // +build windows
  5. package osutil
  6. import "syscall"
  7. func HideFile(path string) error {
  8. p, err := syscall.UTF16PtrFromString(path)
  9. if err != nil {
  10. return err
  11. }
  12. attrs, err := syscall.GetFileAttributes(p)
  13. if err != nil {
  14. return err
  15. }
  16. attrs |= syscall.FILE_ATTRIBUTE_HIDDEN
  17. return syscall.SetFileAttributes(p, attrs)
  18. }
  19. func ShowFile(path string) error {
  20. p, err := syscall.UTF16PtrFromString(path)
  21. if err != nil {
  22. return err
  23. }
  24. attrs, err := syscall.GetFileAttributes(p)
  25. if err != nil {
  26. return err
  27. }
  28. attrs &^= syscall.FILE_ATTRIBUTE_HIDDEN
  29. return syscall.SetFileAttributes(p, attrs)
  30. }