github.com/boyter/gocodewalker@v1.3.2/hidden_windows.go (about)

     1  // SPDX-License-Identifier: MIT OR Unlicense
     2  //go:build windows
     3  // +build windows
     4  
     5  package gocodewalker
     6  
     7  import (
     8  	"os"
     9  	"path"
    10  	"syscall"
    11  )
    12  
    13  // IsHidden Returns true if file is hidden
    14  func IsHidden(file os.FileInfo, directory string) (bool, error) {
    15  	fullpath := path.Join(directory, file.Name())
    16  	pointer, err := syscall.UTF16PtrFromString(fullpath)
    17  	if err != nil {
    18  		return false, err
    19  	}
    20  	attributes, err := syscall.GetFileAttributes(pointer)
    21  	if err != nil {
    22  		return false, err
    23  	}
    24  	return attributes&syscall.FILE_ATTRIBUTE_HIDDEN != 0, nil
    25  }